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;
}
Discussion:
11 comments Page 1 of 2.
Paveen said:
5 years ago
Near used to store 16-bit address that is within the current segment.
While far & ptr typically used to store 32-bit address i.e. outside the current segment.
While far & ptr typically used to store 32-bit address i.e. outside the current segment.
Rajarshi Deb said:
6 years ago
I an not understanding, please anyone explain.
Alfaz raza said:
9 years 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.
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.
Sonia sonawane said:
10 years 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;
}
void incr();
int main()
{
incr();
incr();
incr();
return 0;
}
void incr()
{
auto int i=1;
printf("%d",i);
i=i+1;
}
Jarvis said:
10 years 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?
^
|
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?
Lali said:
10 years ago
@Chilli can you explain how near always take 2 byte and far take 4 byte.
Sruthi said:
1 decade ago
Size of pointer only depends on type on compiler but not on data type. But why this difference?
Deepika said:
1 decade ago
Why near variable takes 2bytes and other variable takes 4bytes but all the variables have same type.
Mayur said:
1 decade ago
Thanks chilli.
Chilli said:
1 decade ago
Near always takes 2 bytes.
Far and huge always takes 4 bytes.
Far and huge always takes 4 bytes.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers