IndiaBIX.com
Search

C Programming - Declarations and Initializations - Discussion

@ : Home > C Programming > Declarations and Initializations > Find Output of Program - 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

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: (Wed, Jun 9, 2010 06:25:00 AM)    
 
I don't know what is far and huge. Can you explain?

Reema said: (Wed, Aug 25, 2010 01:55:25 PM)    
 
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: (Tue, Oct 26, 2010 02:17:48 AM)    
 
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: (Thu, Feb 10, 2011 12:29:26 AM)    
 
#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: (Wed, Feb 23, 2011 06:16:25 AM)    
 
#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: (Fri, Mar 11, 2011 01:49:43 AM)    
 
@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: (Tue, Apr 26, 2011 03:25:32 AM)    
 
1.Explain what is far and huge?
2.were it is used?

Rovin Varshney said: (Sat, Apr 30, 2011 03:40:25 AM)    
 
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: (Wed, Jun 15, 2011 11:41:15 AM)    
 
What is far and huge?

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

Any one answer me?

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

Dhiraj said: (Tue, Jul 5, 2011 03:18:57 PM)    
 
@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: (Wed, Jul 6, 2011 04:32:14 AM)    
 
I don't understand this.

Kamesh said: (Mon, Jul 11, 2011 01:31:06 PM)    
 
Can any body tell me what does mean by

char far *s2;
char huge *s3;

Shefali said: (Fri, Jul 22, 2011 01:01:15 PM)    
 
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: (Sat, Aug 6, 2011 07:38:13 PM)    
 
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: (Tue, Aug 30, 2011 02:07:36 PM)    
 
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: (Tue, Sep 13, 2011 11:48:20 PM)    
 
@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: (Wed, Oct 5, 2011 01:50:22 AM)    
 
Then what is huge pointer? is it same as far pointer.

Deepak said: (Tue, May 8, 2012 12:36:43 PM)    
 
@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: (Fri, May 11, 2012 10:16:00 PM)    
 
char far *s2;
char huge *s3;
WHAT IS THE ROLE OF *S2 AND *S3 ?

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

Rohit said: (Mon, Sep 10, 2012 01:59:50 PM)    
 
How is the answer is 2, 4, 4 explain in depth ?

Amit said: (Wed, Nov 14, 2012 05:31:22 PM)    
 
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: (Wed, Dec 26, 2012 06:06:49 PM)    
 
@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: (Wed, Dec 18, 2013 05:12:17 PM)    
 
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??

Write your comments here:
Name *:     Email:


© 2008-2014 by IndiaBIX™ Technologies. All Rights Reserved | Copyright | Terms of Use & Privacy Policy

Contact us: info@indiabix.com     Follow us on twitter!