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 4 of 6.
Siva Krishna said:
1 decade ago
@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.
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.
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);.
Rohit said:
1 decade ago
How is the answer is 2, 4, 4 explain in depth ?
Sam said:
1 decade ago
What is DOS 16 bit OS ? Where we are using this ? If some other versions present what are they ?
SALVATOR said:
1 decade ago
char far *s2;
char huge *s3;
WHAT IS THE ROLE OF *S2 AND *S3 ?
char huge *s3;
WHAT IS THE ROLE OF *S2 AND *S3 ?
Deepak said:
1 decade ago
@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.
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.
Saraswathi said:
1 decade ago
Then what is huge pointer? is it same as far pointer.
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...?
Poornima said:
1 decade ago
Could you please explain the differences between the exit(0); and exit(1);and also the difference between the return(0); and return(1);.
Lathaa said:
1 decade ago
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.
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.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers