Determine Output:
main()
{
char *str1 = "abcd";
char str2[] = "abcd";
printf("%d %d %d", sizeof(str1), sizeof(str2), sizeof("abcd"));
}
main()
{
char *str1 = "abcd";
char str2[] = "abcd";
printf("%d %d %d", sizeof(str1), sizeof(str2), sizeof("abcd"));
}
A. 2 5 5
B. 2 4 4
C. 8 5 5
D. 2 4 5
Answer: Option C
Solution(By Examveda Team)
In first sizeof, str1 is a character pointer so it gives you the size of the pointer variable. In second sizeof the name str2 indicates the name of the array whose size is 5 (including the 'null' termination character). The third sizeof is similar to the second one.
Join The Discussion
Comments ( 7 )
Related Questions on Pointer
In C, what is a pointer primarily used for?
A. Decision making
B. Code organization
C. Variable declaration
D. Storing values
In C, how do you declare a pointer variable that can store the address of an integer?
A. int *ptr;
B. ptr int;
C. int ptr;
D. ptr *int;
What is the purpose of the '->' operator in C when used with pointers?
A. Arithmetic operation
B. Indirection operator
C. Member access operator
D. Bitwise operation
The answer is 2 5 5
Can you explain how it 8 5 5
2 5 5 is the correct answer
They are using 64 bit compiler so the size of pointer variable is 8 byte in 64 bit compiler... Is it okay friends??
the answer shoud be 2,5,5 as i run the code using tubo c compiler.
cant understand
Hello Shaik,
sizeof(char *) is the size of the pointer, so normally 4 for 32-bit machine, and 8 for 64-bit machine.
its answer is 8 5 5 just know I compile this program