?
What is the output of printf("%d", sizeof("Hello")); in C?
Answer & Solution
Correct Answer:
Option
B
The
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")) 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
Login to post a comment or share your explanation.
Login