Machine-translated by Google. Questions are authored in English.
Top

Discussion

What is the output of this C code?

#include <stdio.h>
    int main()
    {
        enum {ORANGE = 5, MANGO, BANANA = 4, PEACH};
        printf("PEACH = %d\n", PEACH);
    }

 

  • A.PEACH = 3
  • B.PEACH = 4
  • C.PEACH = 5
  • D.PEACH = 6

Answer: C

Correct answer: PEACH = 5

Enumerators continue from the previous value, and an explicit value restarts the sequence from that point.

So ORANGE = 5, MANGO becomes 6, BANANA = 4 resets the count, and PEACH follows at 5. ORANGE and PEACH therefore share the value 5, which C permits. The trap is expecting PEACH to continue from MANGO rather than from the explicitly reset BANANA.

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

Post your comment

Please log in or register to post a comment.