C Programming - Complicated Declarations - Discussion

Discussion Forum : Complicated Declarations - Find Output of Program (Q.No. 12)
12.
What will be the output of the program in Turbo C?
#include<stdio.h>

int main()
{
    char near *near *ptr1;
    char near *far *ptr2;
    char near *huge *ptr3;
    printf("%d, %d, %d\n", sizeof(ptr1), sizeof(ptr2), sizeof(ptr3));
    return 0;
}
4, 4, 8
4, 4, 4
2, 4, 8
2, 4, 4
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
11 comments Page 1 of 2.

Saidarao said:   2 decades ago
Can you explain this please?

Chilli said:   1 decade ago
Near always takes 2 bytes.

Far and huge always takes 4 bytes.

Mayur said:   1 decade ago
Thanks chilli.

Deepika said:   1 decade ago
Why near variable takes 2bytes and other variable takes 4bytes but all the variables have same type.

Sruthi said:   1 decade ago
Size of pointer only depends on type on compiler but not on data type. But why this difference?

Lali said:   1 decade ago
@Chilli can you explain how near always take 2 byte and far take 4 byte.

Jarvis said:   1 decade ago
char near *near *ptr1;
^
|

This "near" does not help in anyway.

1. Try removing "that" near.

2. Try putting "far" or "huge" instead of "that".

----------------------------------------------------
=> the output is still same (2,4,4)
----------------------------------------------------

The question is why?

Sonia sonawane said:   1 decade ago
#include<stdio.h>
void incr();
int main()
{
incr();
incr();
incr();
return 0;
}
void incr()
{
auto int i=1;
printf("%d",i);
i=i+1;
}

Alfaz raza said:   1 decade ago
Guys actually here they introduce three types of pointers, in which first one is near. This pointer can point within the segment or program.

Second one is far pointer it can point to outside the segment and also it can point to large range of address.

Third one is huge pointer it is similar to far pointer. In case of far pointer it is not possible to point to outside the certain boundary, whereas in case of huge pointer if programmer wants the value which is outside the boundary in that situation huge extends its capacity.

Rajarshi Deb said:   7 years ago
I an not understanding, please anyone explain.


Post your comments here:

Your comments will be displayed after verification.