?
What will be printed after compiling and running the following code?
What will be printed after compiling and running the following code?
main()
{
char *p;
printf("%d %d",sizeof(*p), sizeof(p));
}
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.
Join the Discussion
Login to post a comment or share your explanation.
Login{
char *p;
printf("%d %d",sizeof(*p), sizeof(p));
}
ANSWER IS : 1 , 8
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