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 3 of 4.
Nagarjuna said:
1 decade ago
Size of the pointer will take the size is 4 bytes.
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.
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.
Vikas said:
1 decade ago
Thanks sowmy its really a good reference.
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 .
Bharath said:
1 decade ago
Please any one explain about this problem I did't get properly.
Thamil said:
1 decade ago
Need proper clarification regarding this problem.
Kiran said:
1 decade ago
Huge *far *near *ptr1---> is this a single variable?
If it is a single variable we should not use spaces in b/w the variables?
Can any one give me the explination please?
If it is a single variable we should not use spaces in b/w the variables?
Can any one give me the explination please?
Goaku said:
1 decade ago
Can we leave such blank spaces while declearing variables?
Sowmya said:
1 decade ago
http://clanguagestuff.blogspot.com/2011/03/difference-between-far-and-huge.html
Its a real good reference.
Its a real good reference.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers