C Programming Reference
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;
}
-> Solution
Question 2. 

Guess the output of the following code?
int  main ()

{
  printf ( "%lf", (0.99 - 0.9 -0.09);
  return 0;
}
-> Solution

Question 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;
}
-> Solution

Question 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;
}
-> Solution

Question 6. 

Write a program to print "HI",  without any semi colon.
-> Solution Question 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;
}
-> Solution

Question 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;
 }  
-> Solution


Question 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;
}  
-> Solution
Question 10. 

Write a program to multiply two number without using any arithemetic operators (*,+,-,/,%) in C.
-> Solution


Question 11. 

What will be  the output of the following code and why?
#include <stdio.h>

struct data    
   {       
      int a;      
      int b;      
      int c;          
   };    
 
int main()  
{    
  
 struct node  s= { 3, 5,6 };     

struct node *pt = &s;    
printf("%d" ,  *(int*)pt);  

return 0;
}  
-> Solution


Question 12. 

What is the aritmetic operation performed by function on x in relation with n?
int  mystery ( int x , int  n)  
{    


  int val;    
  val =1;        
  if (n>0)     
   {      
     if (n%2 == 1)  
     val = val *x;            
     val = val * mystery(x*x , n/2);    
   }    
return val;

}
-> Solution


Question 13. 

What will be  the output of the following code?
#include <stdio.h>

int main()  
{    
  int  a[5] = {1,2,3,4,5};    
  int *ptr =  (int*)(&a+1);      
 printf("%d %d" , *(a+1), *(ptr-1) );   
 return 0;
 }  
-> Solution


Question 14. 

Output of this program will be?
#include <stdio.h>

void function(int [][3] );         

int main()  
{    
  int a [3][3]= {  { 1,2,3} ,  { 4,5,6} , {7,8,9} };    
  function(a);    
  printf("%d" , a[2][1]); 
  return 0;
 }    

void function ( int b [ ] [3] ) 
  {    
     ++ b;   
      b[1][1] =9; 
  }
 
-> Solution
Question 15. 

State  the output of the following code.
#include <stdio.h>
int main() { int a, b,c, d; a=3; b=5; c=a,b; d=(a,b); printf("c = %d" ,c); printf("\n\nd = %d" ,d); return 0; }
-> Solution


Question 16. 

What will be  the output of the following code and why?
#include <stdio.h>
int main()
{
int x = 40; { int x = 20; printf ("%d ", x); } printf ("\n\n%d",x);
}
-> Solution
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; }
-> Solution


Question 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;  
}  
-> Solution
Question 19. 

Guess  the output of the following code.
#include <stdio.h>
int main() { int i=3; int j; j = sizeof(++i+ ++i); printf("i=%d j=%d", i ,j); return 0; }
-> Solution
Question 20. 

What will be  the output of the following code and why?
#include <stdio.h>
void f1(int *, int); void f2(int *, int); void(*p[2]) ( int *, int); int main() { int a; int b; p[0] = f1; p[1] = f2; a=3; b=5; p[0](&a , b); printf("%d\t %d\t" , a ,b); p[1](&a , b); printf("%d\t %d\t" , a ,b); } void f1( int* p , int q) { int tmp; tmp =*p; *p = q; q= tmp; } void f2( int* p , int q) { int tmp; tmp =*p; *p = q; q= tmp; }
-> Solution
Question 21. 

Output of the following code will be?
#include <stdio.h>

void e(int ); int main( ) { int a; a=3; e(a); return 0; } void e(int n) { if(n>0) { e(--n); printf("%d" , n); e(--n); } }
-> Solution
Question 22. 

What will be  the output of the following code?
#include <stdio.h>
#define ASS Donkey int main()
{
printf ("ASS"); return 0; }
-> Solution
Question 23. 

What is the type of temp below?
typedef int (*test) ( float * , float*) 
 test tmp;  
-> Solution
Question 24. 

Determine  the output of the following code.
#include <stdio.h>

void f(char**); main() { char * argv[] = { "ab" ,"cd" , "ef" ,"gh", "ij" ,"kl" }; f( argv ); } void f( char **p ) { char* t; t= (p+= sizeof(int))[-1]; printf( "%s" , t); }
-> Solution
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;  
}  
-> Solution

Question 26. 

Predict  the output of the following code.
#include <stdio.h>

int main() { char *p; char buf[10] = { 1,2,3,4,5,6,9,8} ; p = (buf+1)[5]; printf("%d" , p); }
-> Solution
 
Collected By Anuj Pathania
  Acknowledgements
  © 2006 cencyclopedia.com