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 1 of 2.
Abhayraj SN said:
8 years ago
Kindly note it carefully.
Near pointer = 2 bytes,
far = 4 bytes,
huge = 4 bytes.
consider given one statement ---- char huge *near *far *ptr1;
sizeof(ptr1) -->> far = 4
sizeof(*ptr1) -->> near = 2
sizeof(**ptr1) -->> huge = 4
As * is included REVERSE back from the END in the statement.
Hope, you will get it. Thanks.
Near pointer = 2 bytes,
far = 4 bytes,
huge = 4 bytes.
consider given one statement ---- char huge *near *far *ptr1;
sizeof(ptr1) -->> far = 4
sizeof(*ptr1) -->> near = 2
sizeof(**ptr1) -->> huge = 4
As * is included REVERSE back from the END in the statement.
Hope, you will get it. Thanks.
(1)
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.
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.
Anand Sharma said:
6 years ago
As pointer contains address (hexadecimal) values not simple integer or char values.
Thus the size of any pointer is 8 bytes.
Thus the size of any pointer is 8 bytes.
King_07 said:
9 years ago
Is there any detailed explanation? I'm sorry but all explanation are not clear.
Thank you.
Thank you.
Dhaval said:
1 decade ago
Can anyone explain the flow of operations going and how the answer is coming to 4.
Chitturi bhavani said:
8 years ago
I did not understand, can some one please explain me in detail?
Pranav said:
7 years ago
Someone, please explain this question in simple way.
Geetha said:
8 years ago
I didn't understand this. Please explains briefly.
Bharathi said:
9 years ago
How near, huge and far is assigned 2 or 4 bytes?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers