Examveda
Examveda

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)

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.

This Question Belongs to C Program >> Arrays And Strings

Join The Discussion

Comments ( 2 )

  1. Anupam Patel
    Anupam Patel :
    7 months ago

    Answer is Correct d

  2. Anupam Patel
    Anupam Patel :
    7 months ago

    What is a correct answer b

Related Questions on Arrays and Strings