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

Determine Output:
main()
{
      char *str1 = "abcd";
      char str2[] = "abcd";
      printf("%d %d %d", sizeof(str1), sizeof(str2), sizeof("abcd"));
}

Answer & Solution
Correct Answer: Option C

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.

Examveda
Question posted by Examveda
Community

Join the Discussion

7 Comments
Hetshri Ved
Hetshri Ved 4 years ago
The answer is 2 5 5
Can you explain how it 8 5 5
Om Chaturvedi
Om Chaturvedi 5 years ago
2 5 5 is the correct answer
Vedant Kulkarni
Vedant Kulkarni 6 years ago
They are using 64 bit compiler so the size of pointer variable is 8 byte in 64 bit compiler... Is it okay friends??
Amit Tiwari
Amit Tiwari 8 years ago
the answer shoud be 2,5,5 as i run the code using tubo c compiler.
Swathi Lakshmi
Swathi Lakshmi 9 years ago
cant understand
Examveda
Examveda 10 years ago
Hello Shaik,
sizeof(char *) is the size of the pointer, so normally 4 for 32-bit machine, and 8 for 64-bit machine.
Shaik Salman
Shaik Salman 10 years ago
its answer is 8 5 5 just know I compile this program