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 3 of 6.
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??
char far *s2;
char huge *s3;
Can anyone explain me??
Amit said:
1 decade ago
Please explain the differences between the exit(0); and exit(1);and also the difference between the return(0); and return(1);.
Prashant said:
1 decade ago
@Sundar
We are talking about sizeof(char) not a sizeof(int)....!!!!
How come it can be 4 rather than becoming 1 or 2...?
We are talking about sizeof(char) not a sizeof(int)....!!!!
How come it can be 4 rather than becoming 1 or 2...?
Reema said:
1 decade ago
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 ?.
And what do you mean by 16-bit offset and 16-bit segment value ?.
Yuvasree said:
8 years ago
I am getting error in 32bit Linux compiler, s2 and s3 was declared. Why I'm getting this error in 32 bit compiler?
Shri Hari Rajeswar said:
5 years ago
Can you please explain how you said like this? because pointer holds same bytes irrespective of the base you use.
Rahul Manjramkar said:
9 years ago
What is the far and huge?
And this code is error can't show output, so please explain in detail program also.
And this code is error can't show output, so please explain in detail program also.
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?
Sam said:
1 decade ago
What is DOS 16 bit OS ? Where we are using this ? If some other versions present what are they ?
Suhas said:
1 decade ago
Guys I'm confuse between the huge and far pointer. Can anybody explain me please?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers