C Programming Reference
 
C Programming Reference >> C  Programming Reference Question Bank >>

28/05/07 - 1074 Views - Ratings :   3.86 of 5 / 14 Votes

Level - Beginner
      

Question -

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

Answer -

  p1 :  4    
 
  p2 : 2 
Explanation -

Well on first thought you will be thinking that values should be same for both pointers but output does not agree to your evaluation. Why?

The minute thing to notice that if observed very very carefully you can notice that the first pointer is a far pointer while the second pointer is normal pointer. As a far pointer is of size 4 bytes and normal pointer is of size 2 bytes, the p1 display a size of 4 while the p2 display the size of 2.

This question is a little tricky because of this eye trick. Next time in a interview when given such a trick c question by examiner, especially when his face has a grin, you can happily smile back :-).

Reader Comments -

Author Comments
Add Comments 


Name :    
Reply :   


Rating :

Code :
Code

 

 
© 2006 cencyclopedia.com