Vidyalelo
C Programming · Q13

Arrays and Strings

Programming · C Programming · question 13

Q13

What is the output of printf("%d", sizeof("Hello")); in C?

A.
8
B.
6
Answer
C.
4
D.
2

Answer: Option B

Solution

Answer: Option B
Solution:
The 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.