What is the output of printf("%d", sizeof("Hello")); in C?
A. 8
B. 6
C. 4
D. 2
Answer: Option B
Solution(By Examveda Team)
Theprintf("%d", sizeof("Hello"))
statement in C is used to determine the size (in bytes) of the string literal "Hello" including the null terminator. In C, string literals are automatically null-terminated.
The string "Hello" consists of 5 characters: 'H', 'e', 'l', 'l', 'o', and it also includes a null terminator ('\0') at the end to mark the end of the string.
So, the total size of the string literal "Hello" is 6 bytes (5 characters + 1 null terminator).
Therefore, the output of
printf("%d", sizeof("Hello"))
will be Option B: 6 because it's the size of the string in bytes, including the null terminator. Join The Discussion
Comments ( 2 )
Related Questions on Arrays and Strings
Answer is Correct d
What is a correct answer b