C Programming - Complicated Declarations - Discussion
Discussion Forum : Complicated Declarations - Find Output of Program (Q.No. 1)
1.
What will be the output of the program?
#include<stdio.h>
int main()
{
char far *near *ptr1;
char far *far *ptr2;
char far *huge *ptr3;
printf("%d, %d, %d\n", sizeof(ptr1), sizeof(ptr2), sizeof(ptr3));
return 0;
}
Discussion:
31 comments Page 2 of 4.
Jangum said:
9 years ago
Thanks, @Abishek.
Sam said:
9 years ago
I don't understand the program statements. Please explain me once.
Vijji said:
9 years ago
Near pointer is used to store 16 bit address.
Far pointer is used to store 32 bit addresses.
Huge pointer is used to store 32 bit addresses.
Far pointer is used to store 32 bit addresses.
Huge pointer is used to store 32 bit addresses.
Abhisek said:
9 years ago
@Madhu.
First, let's understand how to read these.
Simple on:
char c; // c is a character.
char *ptr; // ptr is a pointer to a char.
char far *fptr; // fptr is a far pointer to char.
Remember when we write double points.
char **dptr; // dptr is a pointer to pointer to a char.
In a similar way.
char far *near *prt1; // prt1 is a near pointer to far pointer to char.
Hope it makes sense.
First, let's understand how to read these.
Simple on:
char c; // c is a character.
char *ptr; // ptr is a pointer to a char.
char far *fptr; // fptr is a far pointer to char.
Remember when we write double points.
char **dptr; // dptr is a pointer to pointer to a char.
In a similar way.
char far *near *prt1; // prt1 is a near pointer to far pointer to char.
Hope it makes sense.
Bhasker thapa said:
10 years ago
OUTPUT:
The output size is too large (infinite loop or larger text output).
This is the output when I compiled the above code in India bix compiler, and this does not match with the answer.
The output size is too large (infinite loop or larger text output).
This is the output when I compiled the above code in India bix compiler, and this does not match with the answer.
Madhu said:
1 decade ago
I can't understand the declarations how is it possible to make multiple declarations without being separated by comma.
char far, *near, *ptr1;
I think above declaration is only right.
char far, *near, *ptr1;
I think above declaration is only right.
Satish Bhati said:
1 decade ago
GNU GCC v 4.8 compiler is showing error.
And GCC Compiler (32 Bit Linux Platform) of IndiaBix is showing "The output size is too large (infinite loop or larger text output)".
Why?
And GCC Compiler (32 Bit Linux Platform) of IndiaBix is showing "The output size is too large (infinite loop or larger text output)".
Why?
Mahesh Babu said:
1 decade ago
Sakshi Chopra thanks for the answer Sir.
Vishal and sandeep said:
1 decade ago
Associativity in pointer is right to left... so for
char far *near *ptr1;(think it is like type casting or pointer to pointer).
ptr1 will contain address of (*near) which will be 2 byte and that contain the address of far memory character so it will now 4 byte.
so the sizeof(ptr1)= 2 byte and sizeof(*ptr)= 4 byte.
char far *near *ptr1;(think it is like type casting or pointer to pointer).
ptr1 will contain address of (*near) which will be 2 byte and that contain the address of far memory character so it will now 4 byte.
so the sizeof(ptr1)= 2 byte and sizeof(*ptr)= 4 byte.
Shankar said:
1 decade ago
Thanks sakshi.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers