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.
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?
Jaya phanindra said:
8 years ago
While compiling the given code am getting the below error.
Can anyone explain this please.
Error: expected '=', ',', ';', 'asm' or '__attribute__' before '*' token.
Can anyone explain this please.
Error: expected '=', ',', ';', 'asm' or '__attribute__' before '*' token.
Baahubali said:
8 years ago
What is offset and segment in this case?
Rprabaraj said:
8 years ago
What is mean by segment and offset value? Explain me, please.
Kavipriya said:
8 years ago
What is the output in turboc compiler and Linux compiler?
#include<stdio.h>
main(){
int x=65,y=97;
if('x'>'y')
Print("A");
Print("B");
}
I don't know what concept is there if anyone know that concept can you post the answer friends.
#include<stdio.h>
main(){
int x=65,y=97;
if('x'>'y')
Print("A");
Print("B");
}
I don't know what concept is there if anyone know that concept can you post the answer friends.
Ashwini Shirke said:
8 years ago
Why intially 2 byte output is come?
Manish Motwani said:
8 years ago
Need some assistance, please any kind and knowledgeable person who can help me tell how the output of the c program is affected by 16 bit, 32 bit and 64 bit operating system.
Ani said:
7 years ago
I don't know what is far and huge here, Can you explain?
Kiran BS said:
6 years ago
far and huge is character variables. Here the variables aren't separated by comma.
And as I know the size of pointers is always same so when I compiled and checked it is showed 8, 8, 8 as output, which is the correct answer or even 4, 4, 4 is possible since the format specifier is %d.
And as I know the size of pointers is always same so when I compiled and checked it is showed 8, 8, 8 as output, which is the correct answer or even 4, 4, 4 is possible since the format specifier is %d.
Laxman said:
6 years ago
Sir every pointer has 2 bytes so how *s2, *s3 4 bytes?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers