C Programming - Memory Allocation - Discussion

Discussion Forum : Memory Allocation - Find Output of Program (Q.No. 2)
2.
What will be the output of the program (16-bit platform)?
#include<stdio.h>
#include<stdlib.h>

int main()
{
    int *p;
    p = (int *)malloc(20);
    printf("%d\n", sizeof(p));
    free(p);
    return 0;
}
4
2
8
Garbage value
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
31 comments Page 3 of 4.

Sahikha said:   2 decades ago
P is integer pointer and it stores 2 bytes so sizeof P is 2 bytes

Vinay said:   1 decade ago
If your processor is 16 bit, then 2 if 32 bit then 4, if 64 bit 8.

Vijay kumar said:   6 years ago
The answer is 8 because the size of a pointer is always 8.

Sripadh said:   6 years ago
But if I run this program it is showing the output as 8.
(1)

Suraj said:   8 years ago
Answer is 4 because integer pointer is size is 4byte.

Yash said:   8 years ago
@Vinay and @Raju Naidu are absolutely correct.

Sarvajeet Suman said:   10 years ago
For GCC compiler it's 4 & not 2.

Satish said:   1 decade ago
Vinay absulutely you are right.

Sumedh said:   1 decade ago
Its depend upon a compiler

Ajinkya said:   1 decade ago
For 32 bits it is 4.
(1)


Post your comments here:

Your comments will be displayed after verification.