Single Choice Not Set

QWhat is the output of this C code?

#include <stdio.h>
    #include <string.h>
    int main()
    {
        char *str = "x";
        char c = 'x';
        char ary[1];
        ary[0] = c;
        printf("%d %d", strlen(str), strlen(ary));
        return 0;
    }

ID: #1365 Constant in C Language 2,699 views
Question Info
#1365Q ID
Not SetDifficulty
Constant in C LanguageTopic

Choose the Best Option

Click any option to instantly check if you're correct.

  • A 1 1
  • B 2 1
  • C 2 2
  • D 1 (undefined value)
Correct Answer

Explanation

str is null terminated but ary is not. Output:
$ cc pgm7.c
$ a.out
1 5

Share This Question

Challenge a friend or share with your study group.