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 1 of 6.
Gourvi said:
5 years ago
@For_all.
Here in this question, we have 3 type of pointers that is near, far and huge. And by default in c we have near pointer, for eg: int *p, here size of (p) would be 2 bytes in 16 bit complier. But here far and huge pointers are also being used and there sizeof is 4 bytes.
P.S: Forget about char size as here main focus is on near, far and huge pointers.
And for more clear understanding please refer google.
Here in this question, we have 3 type of pointers that is near, far and huge. And by default in c we have near pointer, for eg: int *p, here size of (p) would be 2 bytes in 16 bit complier. But here far and huge pointers are also being used and there sizeof is 4 bytes.
P.S: Forget about char size as here main focus is on near, far and huge pointers.
And for more clear understanding please refer google.
(2)
Sanjana said:
2 years ago
1. Near Pointer:
The Near Pointer is used to store the 16-bit addresses. It means that they can only reach the memory addresses within the current segment on a 16-bit machine. That is why we can only access the first 64 kb of data using near-pointers.
The size of the near pointer is 2 bytes.
2. Far Pointer:
A far pointer stores the address in two 16-bit registers that allow it to access the memory outside of the current segment. The compiler allocates a segment register to store the segment address, and then another register to store offset within the current segment. The offset is then added to the shifted segment address to get the actual address
The size of the far pointer is 4 bytes.
3. Huge Pointer:
The huge pointer also stores the addresses in two separate registers similar to the far pointer. It has the following characteristics:
In the Huge pointer, both offset and segment address is changed.
The Huge Pointers always compare the absolute addresses, so the relational operation can be performed on it.
The size of the huge pointer is 4 bytes.
The Near Pointer is used to store the 16-bit addresses. It means that they can only reach the memory addresses within the current segment on a 16-bit machine. That is why we can only access the first 64 kb of data using near-pointers.
The size of the near pointer is 2 bytes.
2. Far Pointer:
A far pointer stores the address in two 16-bit registers that allow it to access the memory outside of the current segment. The compiler allocates a segment register to store the segment address, and then another register to store offset within the current segment. The offset is then added to the shifted segment address to get the actual address
The size of the far pointer is 4 bytes.
3. Huge Pointer:
The huge pointer also stores the addresses in two separate registers similar to the far pointer. It has the following characteristics:
In the Huge pointer, both offset and segment address is changed.
The Huge Pointers always compare the absolute addresses, so the relational operation can be performed on it.
The size of the huge pointer is 4 bytes.
(1)
Suhas said:
1 decade ago
Guys I'm confuse between the huge and far pointer. Can anybody explain me please?
Aruna said:
1 decade ago
Can anyone explain in detail about far and huge?
Sri said:
1 decade ago
Can any one give the answer what is meant by far and huge?
Arpita said:
1 decade ago
Can anybody answer the meaning of huge and far in detail?
Pooja said:
10 years ago
Can anybody explain huge pointer in detail?
Sai said:
9 years ago
I can't understood. Anyone can explain in details. Please.
Saranya said:
9 years ago
What is 16-bit segment value and 16-bit offset value?
Satya said:
9 years ago
The far and huge have the same value.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers