C Programming - Declarations and Initializations - Discussion

Discussion Forum : Declarations and Initializations - Find Output of Program (Q.No. 4)
4.
What is the output of the program in Turbo C (in DOS 16-bit OS)?
#include<stdio.h>
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
Explanation:

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).

Discussion:
55 comments Page 3 of 6.

Satya said:   9 years ago
The far and huge have the same value.

Saranya said:   9 years ago
What is 16-bit segment value and 16-bit offset value?

Sai said:   9 years ago
I can't understood. Anyone can explain in details. Please.

Pooja said:   10 years ago
Can anybody explain huge pointer in detail?

Arpita said:   1 decade ago
Can anybody answer the meaning of huge and far in detail?

Sri said:   1 decade ago
Can any one give the answer what is meant by far and huge?

Suhas said:   1 decade ago
Guys I'm confuse between the huge and far pointer. Can anybody explain me please?

Aruna said:   1 decade ago
Can anyone explain in detail about far and huge?

Madhav said:   1 decade ago
Now a days 16 OS: not available in market.

So we are use either 32 bit or 64 bit.

Please ask Q for 32/64 bit compiler not 16/8/4/2/1 bit compiler.

Sapna yadav said:   1 decade ago
How it will print 2,4,4 for pointer it will take 2 byte but for these two lines,

char far *s2;
char huge *s3;

Can anyone explain me??


Post your comments here:

Your comments will be displayed after verification.