C Programming - Complicated Declarations - Discussion
Discussion Forum : Complicated Declarations - Find Output of Program (Q.No. 9)
9.
What will be the output of the program under DOS?
#include<stdio.h>
int main()
{
char huge *near *far *ptr1;
char near *far *huge *ptr2;
char far *huge *near *ptr3;
printf("%d, %d, %d\n", sizeof(ptr1), sizeof(**ptr2), sizeof(ptr3));
return 0;
}
Discussion:
18 comments Page 2 of 2.
Bharathi said:
9 years ago
How near, huge and far is assigned 2 or 4 bytes?
Raj said:
9 years ago
Here basic and easy rule.
Near - 2 bytes, huge - 4 bytes, far -4 bytes.
char huge *near *far *ptr1;
printf ("%d %d %d\n", sizeof (ptr1), sizeof (*ptr1), sizeof (**ptr1));
// Understand this.
// char (huge=**ptr1)(*near==*ptr1)(*far==ptr1)*ptr1;
O/P:
1st ptr1-> 4.
2nd ptr1 -> 2.
3rd ptr1-> 4.
Near - 2 bytes, huge - 4 bytes, far -4 bytes.
char huge *near *far *ptr1;
printf ("%d %d %d\n", sizeof (ptr1), sizeof (*ptr1), sizeof (**ptr1));
// Understand this.
// char (huge=**ptr1)(*near==*ptr1)(*far==ptr1)*ptr1;
O/P:
1st ptr1-> 4.
2nd ptr1 -> 2.
3rd ptr1-> 4.
Dhaval said:
1 decade ago
Can anyone explain the flow of operations going and how the answer is coming to 4.
Satheesh said:
1 decade ago
Can anyone explain this code in detail?
Ravi raushan said:
1 decade ago
As we know pointer size is 2 bytes(offset value), but far&huge pointer has two part 16-bit:segment value as well as offset value.
The 'near' is having only segment value,so ptr1 size is 4 byte,**ptr2 size is 2 byte, pr3 size is 2 byte.
The 'near' is having only segment value,so ptr1 size is 4 byte,**ptr2 size is 2 byte, pr3 size is 2 byte.
Saravana kumar said:
1 decade ago
Explain me please.
Praveen said:
1 decade ago
Can any one explain ?
Bhavana said:
1 decade ago
Can any1 explain me this stuff......:)
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers