C Programming - Declarations and Initializations - Discussion

Discussion Forum : Declarations and Initializations - Find Output of Program (Q.No. 4)
What is the output of the program in Turbo C (in DOS 16-bit OS)?
int main()
    char *s1;
    char far *s2;
    char huge *s3;
    printf("%d, %d, %d\n", sizeof(s1), sizeof(s2), sizeof(s3));
    return 0;
2, 4, 6
4, 4, 2
2, 4, 4
2, 2, 2
Answer: Option

Any pointer size is 2 bytes. (only 16-bit offset)
So, char *s1 = 2 bytes.
So, char far *s2; = 4 bytes.
So, char huge *s3; = 4 bytes.
A far, huge pointer has two parts: a 16-bit segment value and a 16-bit offset value.

Since C is a compiler dependent language, it may give different output in other platforms. The above program works fine in Windows (TurboC), but error in Linux (GCC Compiler).

54 comments Page 1 of 6.

Shri Hari Rajeswar said:   2 years ago
Can you please explain how you said like this? because pointer holds same bytes irrespective of the base you use.

Dipak said:   2 years ago
No, it's wrong because every pointer has same size irrespective to its base type so its either 4 bytes or 8 bytes depend upon the compiler 32 bit or 64 bit irrespectively.

Gourvi said:   3 years ago

Here in this question, we have 3 type of pointers that is near, far and huge. And by default in c we have near pointer, for eg: int *p, here size of (p) would be 2 bytes in 16 bit complier. But here far and huge pointers are also being used and there sizeof is 4 bytes.

P.S: Forget about char size as here main focus is on near, far and huge pointers.

And for more clear understanding please refer google.

Amol said:   3 years ago
@Sirji if you used * as like above example then you got an error.

Laxman said:   4 years ago
Sir every pointer has 2 bytes so how *s2, *s3 4 bytes?

Kiran BS said:   4 years ago
far and huge is character variables. Here the variables aren't separated by comma.

And as I know the size of pointers is always same so when I compiled and checked it is showed 8, 8, 8 as output, which is the correct answer or even 4, 4, 4 is possible since the format specifier is %d.

Ani said:   4 years ago
I don't know what is far and huge here, Can you explain?

Manish Motwani said:   6 years ago
Need some assistance, please any kind and knowledgeable person who can help me tell how the output of the c program is affected by 16 bit, 32 bit and 64 bit operating system.

Ashwini Shirke said:   6 years ago
Why intially 2 byte output is come?

Kavipriya said:   6 years ago
What is the output in turboc compiler and Linux compiler?

int x=65,y=97;

I don't know what concept is there if anyone know that concept can you post the answer friends.

Post your comments here:

Your comments will be displayed after verification.