ExamVeda
Login
Home
This question belongs to C Program Pointer
Pointer
?

What will be printed after compiling and running the following code?
main() 
{ 
    char *p; 
    printf("%d %d",sizeof(*p), sizeof(p));
}

Answer & Solution
Correct Answer: Option B

The sizeof() operator gives the number of bytes taken by its operand. p is a character pointer, which needs one byte for storing its value (a character). Hence sizeof(*p) gives a value of 1. Since it needs two bytes to store the address of the character pointer sizeof(p) gives 2.

Examveda
Question posted by Examveda
Community

Join the Discussion

3 Comments
Pratik Kumar
Pratik Kumar 9 years ago
main()
{
char *p;
printf("%d %d",sizeof(*p), sizeof(p));
}
ANSWER IS : 1 , 8
Examveda
Examveda 11 years ago
The size of the pointer is equal to the size of integer because pointer always holds address values and address are integer.The size of integer depends upon many things like architecture, operating system etc because of which you are getting different value.

Size of pointer in different IDE
Compiler ---------- Size of Integer ------ Size of Integer Pointer
Borland C/C++ ----- 2 Bytes ------ 2 Bytes
Turbo C/C++ ----- 2 Bytes ------ 2 Bytes
Visual C++ ----- 4 Bytes ------ 4 bytes
Sri Nidhi
Sri Nidhi 11 years ago
size of any pointer is 4bytes for 32bit machine and 8 bytes for 64 bit machine...in ur solutions mentioned it has 2 bytes in most of sizeof pointer calculations.