C Programming - Complicated Declarations - Discussion

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

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

P.yoga priya said:   1 year ago
@All.

Here is my coding.

#include<stdio.h>
int main()
{
int *a;
float *b;
char *c;
double *d;
int i;
float j;
char k;
double l;
a=&i;
b=&j;
c=&k;
d=&l;
printf("%d",sizeof(a));
printf("%d",sizeof(b));
printf("%d",sizeof(c));
printf("%d",sizeof(d));
}


Output:888.

Sujata junare said:   3 years ago
Thanks all.

Sabari Ganesh said:   4 years ago
What are near, far and huge pointers?

These are some old concepts used in 16 bit intel architectures in the days of MS DOS, not much useful anymore.

Near pointer is used to store 16 bit addresses means within current segment on a 16 bit machine. The limitation is that we can only access 64kb of data at a time.

A far pointer is typically 32 bit that can access memory outside current segment. To use this, compiler allocates a segment register to store segment address, then another register to store offset within current segment.

Like far pointer, huge pointer is also typically 32 bit and can access outside segment. In case of far pointers, a segment is fixed. In far pointer, the segment part cannot be modified, but in Huge it can be.

Simran said:   4 years ago
Near ptr has a memory of 2bytes. Far and huge ptr have a memory of 4 bytes. Hence the output is 2, 4, 4.

Sureka said:   4 years ago
I am not getting this, please explain me.

Saurabh said:   4 years ago
Can you please tell me how to read the below line?

char far *near *ptr1;

Pradeep said:   5 years ago
Byte allocation near-2, far, huge-4 so ptr1 refer near so 2bytes, ptr2, 3 refer far & huge so 4 bytes.

Manoja V. said:   6 years ago
Thanks @Hari.

Swetha said:   6 years ago
Thanks @Abhisek.

Arun yadav said:   6 years ago
It's valid in turbo c.

For GCC there is no such concept of near and far,
For GCC it's 4 4 4.


Post your comments here:

Your comments will be displayed after verification.