Top

Discussion

What is the output of this C code?

#include 
    #define MAX 2
    enum bird {SPARROW = MAX + 1, PARROT = SPARROW + MAX};
    int main()
    {
        enum bird b = PARROT;
        printf("%d\n", b);
        return 0;
    }

 

  • A.Compilation error
  • B.5
  • C.Undefined value
  • D.2

Answer: B

MAX value is 2 and hence PARROT will have value 3 + 2.

Output:
$ cc pgm6.c
$ a.out
5

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

Post your comment