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.
Pavan said:
1 decade ago
Exp: far, near and huge pointer are used in dos only. Because there is only one mb memory for accessing. 1mb memory is divided into segment.
There are various segment like cs(code segment), ss(stack segment), ds(data segment) and more like extra segment etc.
Such type of pointer are used to access the memory.
There are various segment like cs(code segment), ss(stack segment), ds(data segment) and more like extra segment etc.
Such type of pointer are used to access the memory.
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.
Naseeb said:
1 decade ago
What is GCC compiler?
Jaswanth said:
1 decade ago
Any pointer holds 4 bytes of memory in gcc compiler.
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;
SRIJAN said:
1 decade ago
Whats the size of near, huge and far pointer ?
(1)
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)
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.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers