C Programming - Complicated Declarations - Discussion
Discussion Forum : Complicated Declarations - Find Output of Program (Q.No. 3)
3.
What will be the output of the program?
#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:
31 comments Page 2 of 4.
SHUBHAM AGNIHOTRI said:
1 decade ago
char huge *near *far *ptr1;
here *ptr1 is huge pointer
here **ptr1 is near pointer
here ***ptr1 is far pointer.
Nw take it similarly in al.l cases & the o/p is justified .
here *ptr1 is huge pointer
here **ptr1 is near pointer
here ***ptr1 is far pointer.
Nw take it similarly in al.l cases & the o/p is justified .
Purnima prasad said:
1 decade ago
char huge*near*far*ptr1;
here *ptr1 is near pointer
**ptr1 is huge pointer
and then output will be justified.
here *ptr1 is near pointer
**ptr1 is huge pointer
and then output will be justified.
Shashi said:
1 decade ago
Treat expression as pointer pointing to pointer.
E.g. char huge*near*far*ptr1 means ptr1 points to far type (or say address of far type) ; far is again pointing to near type and near to huge.
Thus ptr--> 4 bytes (far)
*ptr-->2 bytes (near)
**ptr-->4 bytes (huge)
This happened becausse associativity of pointer is right to left.
E.g. char huge*near*far*ptr1 means ptr1 points to far type (or say address of far type) ; far is again pointing to near type and near to huge.
Thus ptr--> 4 bytes (far)
*ptr-->2 bytes (near)
**ptr-->4 bytes (huge)
This happened becausse associativity of pointer is right to left.
Nagarjuna said:
1 decade ago
Size of the pointer will take the size is 4 bytes.
Abhijit_softlove said:
1 decade ago
char x *y *z *ptr; / x y &z near huge or far
sizeof(ptr)= sizeof(z)
sizeof(*ptr)= sizeof(y)
sizeof(**ptr)= sizeof(x)
sizeof(ptr)= sizeof(z)
sizeof(*ptr)= sizeof(y)
sizeof(**ptr)= sizeof(x)
SRIJAN said:
1 decade ago
Whats the size of near, huge and far pointer ?
(1)
Praveen said:
1 decade ago
size of near pointer is 2 bytes;
sizeof huge pointer is 4 bytes;
sizeof far pointer is 4 bytes;
sizeof huge pointer is 4 bytes;
sizeof far pointer is 4 bytes;
Jaswanth said:
1 decade ago
Any pointer holds 4 bytes of memory in gcc compiler.
Naseeb said:
1 decade ago
What is GCC compiler?
Sumasree said:
1 decade ago
It's supports multiple languages and also portable runs on all available platforms and free s/w, but turbo C don't have these all.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers