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 6 of 6.
Bharadwaj said:
1 decade ago
#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
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
Gangadhararao said:
1 decade ago
#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?
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?
Kim Joe said:
1 decade ago
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 .
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 ?.
Ranjith said:
2 decades ago
I don't know what is far and huge. Can you explain?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers