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;
}
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 5 of 6.
Shefali said:
1 decade ago
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 .
(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 .
Kamesh said:
1 decade ago
Can any body tell me what does mean by
char far *s2;
char huge *s3;
char far *s2;
char huge *s3;
Jeyanthi said:
1 decade ago
I don't understand this.
Dhiraj said:
1 decade ago
@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.
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.
Neethu said:
1 decade ago
Explain, in which cases we were used these far and huge ?
Reddy said:
1 decade ago
How they are using "*" symbol for variable declaration? i.e. *s1, *s2 n *s3
Any one answer me?
Any one answer me?
Vinu said:
1 decade ago
What is far and huge?
Rovin varshney said:
1 decade ago
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.
char far *s2;
char huge *s3;
Can anyone explain these three line, whether it is pointer or simple variable declaration. Its so much confusing.
Kavita.C.Karjagar said:
1 decade ago
1.Explain what is far and huge?
2.were it is used?
2.were it is used?
Sundar said:
1 decade ago
@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).
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).
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers