C Programming - Declarations and Initializations - Discussion

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;
}

[A]. 2, 4, 6
[B]. 4, 4, 2
[C]. 2, 4, 4
[D]. 2, 2, 2

Answer: Option C

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


Ranjith said: (Jun 9, 2010)  
I don't know what is far and huge. Can you explain?

Reema said: (Aug 25, 2010)  
I dont know what is far and huge. Can you explain ?

And what do you mean by 16-bit offset and 16-bit segment value ?.

Kim Joe said: (Oct 26, 2010)  
These concepts come into picture when working with DOS where memory is limited to 1 MB and CPU registers are 16bit wide,so to access more than 16bit data the memory was accessed with offset:segment combination using far and huge,but in 32 bit compilers these keywords are obsolete .

Gangadhararao said: (Feb 10, 2011)  
#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;
}

How is the answer is 2,4,4 explain in depth?

Bharadwaj said: (Feb 23, 2011)  
#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;
}

How the answer is 2,4,4?
Actually I compiled and I got the output as 4,4,4
So clarify this once

Sundar said: (Mar 11, 2011)  
@All

sizeof(int) = 2 bytes in 16 bit platform. (Turboc Under DOS)
sizeof(int) = 4 bytes in 32 bit platform. (GCC under Linux, C++ under Windows)

Like the same lot of things to be considered depending upon the platform.

All the answers given on this website are based on 16-bit platform (Turbo C under DOS).

Kavita.C.Karjagar said: (Apr 26, 2011)  
1.Explain what is far and huge?
2.were it is used?

Rovin Varshney said: (Apr 30, 2011)  
char *s1;
char far *s2;
char huge *s3;

Can anyone explain these three line, whether it is pointer or simple variable declaration. Its so much confusing.

Vinu said: (Jun 15, 2011)  
What is far and huge?

Reddy said: (Jun 29, 2011)  
How they are using "*" symbol for variable declaration? i.e. *s1, *s2 n *s3

Any one answer me?

Neethu said: (Jul 1, 2011)  
Explain, in which cases we were used these far and huge ?

Dhiraj said: (Jul 5, 2011)  
@Reddy

Here *s1 means its a pointer variable which is of character type, means the pointer s1 points to some other variable which is of character type and can access that character variable.

Jeyanthi said: (Jul 6, 2011)  
I don't understand this.

Kamesh said: (Jul 11, 2011)  
Can any body tell me what does mean by

char far *s2;
char huge *s3;

Shefali said: (Jul 22, 2011)  
In a generic OS , memory is organised in a segment:offset fashion. Now say,it is of "X" MB and this "X" MB is made up of say "S" number of segments of each segment having "B" Bytes where S*B Bytes=X MB.

(char *s)-> Pointer: A near pointer is that which will only point within the current segment say segment 3 (there are S number of segments numbered 0 to S-1) by containing only offset .

(char far *s1) :=> Far Pointer: A far pointer is that which will point anywhere in the X MB across segments by containing segment+offset .
The numbers X,S and B vary across diff operating system memory models under which you are programming .

Lathaa said: (Aug 6, 2011)  
A Null pointer is one which does not refer to any thing.

Far pointer refers to an address which not in the same segment where pointer is defined.

Near pointer refers to an address in the same segment where the pointer is defined.

Poornima said: (Aug 30, 2011)  
Could you please explain the differences between the exit(0); and exit(1);and also the difference between the return(0); and return(1);.

Prashant said: (Sep 13, 2011)  
@Sundar

We are talking about sizeof(char) not a sizeof(int)....!!!!

How come it can be 4 rather than becoming 1 or 2...?

Saraswathi said: (Oct 5, 2011)  
Then what is huge pointer? is it same as far pointer.

Deepak said: (May 8, 2012)  
@Saraswathi

Huge pointers are normalized to have the highest possible segment for a given address, so size would be same as far pointer i.e. 4 byte (16 bit segment value +16 bit offset value)

Difference between far and huge pointer is of the highest possible segment.

Salvator said: (May 11, 2012)  
char far *s2;
char huge *s3;
WHAT IS THE ROLE OF *S2 AND *S3 ?

Sam said: (Jun 27, 2012)  
What is DOS 16 bit OS ? Where we are using this ? If some other versions present what are they ?

Rohit said: (Sep 10, 2012)  
How is the answer is 2, 4, 4 explain in depth ?

Amit said: (Nov 14, 2012)  
Please explain the differences between the exit(0); and exit(1);and also the difference between the return(0); and return(1);.

Siva Krishna said: (Dec 26, 2012)  
@Amit and Poornima.

Whenever a program encounters the instruction
exit(0);
It means it sent a 0 to operating system which means normal termination of the program and same is entered in the system log
And

Whenever a program encounters the instruction
exit(1);
It means it sent a 1 to operating system which means abnormal termination and it enters an error termination in the system log.

Note:
0 means successful termination.
1 or non-zero abnormal termination.

Conclusion:
Both are used to termination only. but the difference to indicate to the OS and a professional programming.

Sapna Yadav said: (Dec 18, 2013)  
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??

Madhav said: (Jun 21, 2014)  
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.

Aruna said: (Sep 23, 2014)  
Can anyone explain in detail about far and huge?

Suhas said: (Feb 24, 2015)  
Guys I'm confuse between the huge and far pointer. Can anybody explain me please?

Sri said: (Mar 4, 2015)  
Can any one give the answer what is meant by far and huge?

Arpita said: (Mar 17, 2015)  
Can anybody answer the meaning of huge and far in detail?

Pooja said: (Dec 24, 2015)  
Can anybody explain huge pointer in detail?

Sai said: (Mar 7, 2016)  
I can't understood. Anyone can explain in details. Please.

Saranya said: (May 17, 2016)  
What is 16-bit segment value and 16-bit offset value?

Satya said: (May 23, 2016)  
The far and huge have the same value.

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.