πŸ“Š C Programming
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
πŸ’¬ Discuss
βœ… Correct Answer: (C) 5,6

Explanation: 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.

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.

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
279
Total Visits
πŸ“½οΈ
3 y ago
Published
πŸŽ–οΈ
Chandani
Publisher
πŸ“ˆ
85%
Success Rate