C Programming Language Question Bank -
This is a Constantly Updated Question Bank of C Programming Language. It aims to cover easy as well difficulty and tricky C Programming Questions from all possible topics.
Also C/C++ questions are often asked in interviews, so these questions can also come handy in preparing for C/C++ Interview Questions.
One or More question will be added each day.
Question 1.Determine the output of the following code?
int main ()
{
char far *p1,*p2;
printf ( " p1 : %d \n\n p2 : %d", sizeof (p1), sizeof(p2));
return 0;
}
Question 2.
Guess the output of the following code?
int main ()
{
printf ( "%lf", (0.99 - 0.9 -0.09);
return 0;
}
-> SolutionQuestion 3.
What will be the output of the following code and why?
int main() { unsigned int y = 12; int x = -2;
if(x>y) printf ("x is greater"); else printf ("y is greater");
return 0; }
-> SolutionQuestion 4.
Write a program to find and print the given number is odd or even, Using only one printf (output) statement, no conditional Statement and no logical,relational and arithmatic operators. -> Solution
Question 5.
Predict the output of the following code and why?
#include <stdio.h>
int main() { int i=012; int j=046; int k=056; printf("i=%d",i); printf("j=%d",j); printf("k=%d",k);
return 0; }
-> SolutionQuestion 6.
Write a program to print "HI", without any semi colon. -> SolutionQuestion 7.
What will be the output of the following code and why?
#include <stdio.h>
int main() { int x,y; x = 5; y = ++x * ++x; printf("value of x = %d and value of y = %d\n",x,y);
return 0; }
-> SolutionQuestion 8.Consider the following C source code and guess its output?
int counter (int value)
{
static int count =0;
count = count +value;;
return count;
}
int main()
{
int i , j;
for (i=0; i <=5; i++)
j = counter(i);
printf ("J = %d", j);
return 0;
}
-> SolutionQuestion 9.
What will be output of this C Code Snipet?
#include<setjmp.h>
#include<stdio.h>
static jmp_buf buf;
int main()
{
volatile int b;
int a;
b =3;
a = 3;
if(setjmp(buf)!=0)
{
printf("A = %d ", a);
printf("\n\nB = %d ", b);
exit(0);
}
b = 5;
a = 5;
longjmp(buf , 1);
return 0;
}
Question 17.
What will be the output of the following code?
#include <stdio.h>
int main()
{
int a[][3] = { 1,2,3 ,4,5,6};
int (*ptr)[3] =a;
printf("%d\n\n %d " ,(*ptr)[1], (*ptr)[2] );
++ptr;
printf("\n\n%d\n\n%d" ,(*ptr)[1], (*ptr)[2] );
return 0;
}
-> SolutionQuestion 18.
Which functions of the below 3 functions misuses pointers and why?
int *f1(void)
{
int x =10;
return(&x);
}
int *f2(void)
{
int*ptr;
*ptr =10;
return ptr;
}
int *f3(void)
{
int *ptr;
ptr=(int*)
malloc(sizeof(int));
return ptr;
}
Question 25.
Determine the output of the following program.
#include<stdarg.h>
int ripple ( int , ...);
int main()
{
int num;
num = ripple ( 3, 5,7);
printf( " %d" , num);
return 0;
}
int ripple (int n, ...)
{
int i , j;
int k;
va_list p;
k= 0;
j = 1;
va_start( p , n);
for (; j<n; ++j)
{
i = va_arg( p , int);
for (; i; i &=i-1 )
++k;
}
return k;
}