C Programming Reference >> C Programming Reference Question Bank >>
28/05/07 - Views - Ratings :    4.27 of 5 / 70 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 -
| sunny
|
well , was a easy question but need some brains
|
| Sunny
|
well , was a easy question but need some brains to work on it :--))
|
| Basudeba Rath
|
well, was a easy but need more efford towards the question.
|
| Ashish Kumar
|
well, was difficult but it was mind blowing.
|
| Avinash Vijayvergia
|
eye 4 details. My answer was wrong, 'll take care :)
|
| janaki
|
well, was a wonderful question. ok i impore my knowlange
|
| Prabin Sharma
|
well,its a very good question......actually thanx for pointing out that eye statement..........
|
| cm
|
Funny ! what the heck to trick down by using tiny 'far' when candidate knows to use "Sizeof" as well as knowing 'far'(but skips out unknowingly). Sounds like people wanted to show off their ego and wants others to be aware of their greatness.
|
| shivam singal
|
well,this is good questions for new students but we need some more questions
|
| Rabi Narayan
|
very good question
|
| hemant sharma
|
i need all c#question on my email id that is om.heman@gmail.com
|
| chinu chauhan
|
i need all c,c++ related question with solution on my email id swatichauhan1406@gmail.com
|
| kunal singh
|
really this is tricky question.thank you
|
| rupika
|
i need all c,c++ question with solution on my id rupika.arora2007@gmail.com
|
| Rohit
|
Well, this was an easy question, but needs clear fundamental concepts
|
| devendra
|
it was a very simple question
|
| nagesh kumar
|
s boss.....thanzzz..for dis Q
|
| Shoukat Ali
|
Good Tricky Question
|
|