C

Chandani • 9.82K Points
Tutor III

Q. What will be the output of the following C code?

Code:
#include <stdio.h>

int main()
{
    char str1[] = { 'H', 'e', 'l', 'l', 'o' };
    char str2[] = "Hello";

    printf("%ld,%ld", sizeof(str1), sizeof(str2));

    return 0;
}
  • (A) 5,5
  • (B) 6,6
  • (C) 5,6
  • (D) None of these

Explanation by: Chandani
str1 is initialized with the characters and there are only 5 characters. Thus, the length of the str is 5. While, str2 is initialized with the string "Hello", when we initialized the string in this way - a null ('\0') character is inserted after the string. Thus, the length of str2 is 6.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.


Question analytics