ExamVeda
Login
Home
This question belongs to C Program Arrays And Strings
Arrays and Strings
?

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

Answer & Solution
Correct Answer: Option B
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.
Examveda
Question posted by Examveda
Community

Join the Discussion

2 Comments
Anupam Patel
Anupam Patel 3 years ago
Answer is Correct d
Anupam Patel
Anupam Patel 3 years ago
What is a correct answer b