Determine Output:
void main()
{
char *p;
printf("%d %d", sizeof(*p), sizeof(p));
}
void main()
{
char *p;
printf("%d %d", sizeof(*p), sizeof(p));
}
A. 1 1
B. 1 2
C. 2 1
D. 2 2
Answer: Option B
Solution(By Examveda Team)
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
Comments ( 3 )
Related Questions on C Miscellaneous
Determine output:
void main()
{
int const *p=5;
printf("%d", ++(*p));
}
A. 6
B. 5
C. Garbage Value
D. Compiler Error
A. mmm nnn aaa
B. mmmm nnnn aaaa
C. Compiler Error
D. None of These
A. I hate Examveda
B. I love Examveda
C. Error
D. None of These
Determine Output:
void main()
{
static int var = 5;
printf("%d ", var--);
if(var)
main();
}
A. 5 5 5 5 5
B. 5 4 3 2 1
C. Infinite Loop
D. None of These
size of pointer is 8 bytes for 64 bit OS
size of pointer is 4 bytes for 32 bit OS
when i executed this code, it gave an output :1 4
When I execute the code, I got output as 1 8