char fun()
{
char c = 'A';
printf("Hello World");
return c;
}
main()
{
printf("%d", sizeof(fun()));
}
Output is 1.Even if this is function pointer, the sizeof will get the return type
and returns the size of that data type. Here, the return type is char, so the output
is 1.
#include<stdio.h>
main()
{
int a = 10, b = 20, c = 0;
printf("%d %d %.0d", a, b, c);
}
Output will be "10 20".The %.0d forces compiler to print non negative values. As
c is 0, it will not be printed.
if(condition)
{
printf("Hello");
}
else
{
printf("world");
}
Condition will be fclose(stdout). It will close the stdout file handle and no output
will be printed.
49) Guess the output or error?
#include<stdio.h>
main()
{
int x = 'Aa';
printf("%#x", x);
}
#include<stdio.h>
main()
{
int array[] = {[0] = 1, [1] = 2, [2] = 3 };
printf("%d %d %d\n", array[0], array[1], array[2]);
}
#include <stdio.h>
main()
{
int a[10] = {0,1,2,3,4,5,6,7,8,9};
printf(%d, 1[a]);
}
Output of this program is 1.The a[1] expression is equivalent to *(a + 1) and 1[a]
is equivalent to *(1 + a). Both of them are same. So, 1[a] will return the value of
a[1].
52) Print the output of this C program using "-->" operator ?
#include <stdio.h>
main()
{
int i = 10;
while(i --> 0)
{
#include <stdio.h>
struct A
{
unsigned int i1 : 3;
unsigned int i2 : 4;
};
main()
{
struct A a = { 15, 63};
printf("%d %d\n", a.i1, a.i2);
}
#include <stdio.h>
#define A(a,b) a##b
#define B(a) #a
#define C(a) B(a)
main()
{
printf("%s\n",C(A(1,2)));
printf("%s\n",B(A(1,2)));
}
arguments and will raise an error saying the mismatch between number of
arguments.
56) Guess the output of Sizeof operator inside expression program?
#include <stdio.h>
main()
{
int i = 10;
printf("sizeof(++i) is: %d\n", sizeof(++i));
printf("i : %d\n",i);
}
sizeof(++i) is: 4
i : 10
The sizeof operator is evaluated during compile time and also the expression
inside sizeof is not evaluated. The sizeof just takes the type of the expression.
Here sizeof(++i) is same as sizeof(int).
57) Print the output of this C program using Octel and Decimal?
#include <stdio.h>
main()
{
int a[] = {0001,0010,0100,1000};
int i;
Output
a[0] : 1
a[1] : 8
a[2] : 64
a[3] : 1000
#include<stdio.h>
main()
{
int a;
a = (int)sizeof(!2.3);
printf(%d, a);
Output is 4.The '!' operator takes an argument and return 1 if the value is 0 and
0 otherwise. So, !2.3 is 0. To sizeof 0 is an integer and so the output is 4.
59) Print the output of C program given below using strlen and sizeof
operator?
#include<string.h>
#include <stdio.h>
main()
{
printf("%d %d", sizeof("string"), strlen("string"));
}
Output is "7 6".The sizeof return the number of characters including the null
character, but strlen returns number of characters without null character.
60) Write a program to check whether a liked list is circular or not?
The following function checks whether a linked list is circular or not and return
1 if true. Otherwise it returns 0.
{
if((NULL == fast) || (NULL == fast->next))
{
return 0;
}
else if((fast == slow) || (fast->next == slow))
{
return 1;
}
else
{
slow = slow->next;
fast = fast->next->next;
}
}
}
61) Guess the output of this C program having a pointer in the main
function?
#include<stdio.h>
void func(int *a)
{
int x = 1;
a = &x;
}
main()
{
int i = 2;
int *p = &i;
func(p);
printf("%d", *p);
}
Output is 2.The pointer a in function func is a local copy of pointer p. So, even if
we assign another location to a, it will not be reflected on the p in main
function. The p will point to location of i and will print 2 as result.
Page 4 of 4
<< Prev
4 Next
You are here: Home > Interview Questions > C and C++ Interview Questions and Answers > Advanced C
Interview Questions and Answers for Experienced
Ads by Google
Popular Posts
HR Interview Questions and Answers
Database and SQL Interview Questions and Answers for Freshers, Experienced
Related Articles
C++ Interview Questions and Answers for Freshers, Experienced
Embedded C Interview Questions and Answers
C Interview Questions and Answers for Freshers
C# OOPS Interview Questions and Answers
.Net Framework Interview Questions and Answers
ADO.Net Interview Questions and Answers for Freshers, Experienced
ASP.Net Interview Questions and Answers
ASP.Net MVC Interview questions and Answers
WCF Interview Questions and Answers
ASP.Net Web API Interview Questions
Top 80 + SQL Query Interview Questions and Answers with Examples
Database/SQL Interview Questions and Answers for Freshers, Experienced
Oracle Interview Questions and Answers on SQL Queries and Database Theory
Advanced SQL Interview Questions and Answers
Popular Categories
Database Interview Questions and Answers
.Net Interview Questions and Answers
Core Java Interview Questions and Answers
C Interview Questions and Answers
HR Interview Questions and Answers
Aptitude Test - Tips, Tricks and Shortcuts
Email Newsletter
Enter your Email Address and get interesting updates
Subscribe
Quick Links
Home
B.E Projects
Careers Jobs
Tutorials
Interview Questions
Blog
Placement Test
Forum
Seminar Topics
Quick Contacts
Follow us on
E: info@a4academics.com
W: www.a4academics.com