C Programming - Structures, Unions, Enums - Discussion

Discussion Forum : Structures, Unions, Enums - Find Output of Program (Q.No. 9)
9.
What will be the output of the program in 16-bit platform (under DOS)?
#include<stdio.h>

int main()
{
    struct node
    {
        int data;
        struct node *link;
    };
    struct node *p, *q;
    p = (struct node *) malloc(sizeof(struct node));
    q = (struct node *) malloc(sizeof(struct node));
    printf("%d, %d\n", sizeof(p), sizeof(q));
    return 0;
}
2, 2
8, 8
5, 5
4, 4
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
36 comments Page 4 of 4.

NRV said:   1 decade ago
The Value Depends on the Compiler .. If Itz running on 16 bit Compiler the value would be 2,2 (Because the pointer would always occupy 2 bytes)..

Hiriyo said:   1 decade ago
I am with you mohansai you are right.

Mohansai said:   1 decade ago
The size of int is 4 bytes and the struct node *link; is also 4 bytes.

Now the size of the structure is 8 bytes so when you are allocating the memory the size if p & q is 8, 8 in linux gcc compiler I am compiling and telling to you.

Rohit Kshirsagar-Solapur said:   1 decade ago
The Pointer always have 2 byte if they have integer,.char, float pointer.

int *a
cahr *b
float *c

a,b,c are same size of byte b'coz it store only address of variable if you have TURBOC3 it will bo 2 and you have VC++ then it will give 4.

Sundar said:   2 decades ago
Hi Guys,

If we run this program in DOS (compiled with Turbo C), it will show the output as 2, 2. Because it is a 16-bit platform. If you compile in a 32-bit platform like Linux (compiled with GCC compiler), it will show 4, 4 as the output.

The online compiler given in this websites is a 32 bit (Linux) platform. Show it will show the output as 4, 4.

Hope you understand better. Have a nice day.!

Chandresh said:   2 decades ago
This is because pointer variable always occupy 2 bytes irrespective of their usage.


Post your comments here:

Your comments will be displayed after verification.