Top

Discussion

What is the output of this C code?

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

 

  • A.1 1
  • B.2 1
  • C.2 2
  • D.1 (undefined value)

Answer: D

str is null terminated but ary is not.

Output:
$ cc pgm7.c
$ a.out
1 5

No comment is present. Be the first to comment.
Loading…

Post your comment