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

Discussion

What will be the output of the following C code?

#include <stdio.h>
    int main()
    {
        int one = 1, two = 2;
        #ifdef next
        one = 2;
        two = 1;
        #endif
        printf("%d, %d", one, two);
    }

 

  • A.1, 1
  • B.1, 2
  • C.2, 1
  • D.2, 2

Answer: B

Correct answer: 1, 2

next is never defined, so #ifdef next is false and the two assignments between it and #endif are removed before compilation. The variables keep their initial values, and the program prints 1, 2.

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

Post your comment

Please log in or register to post a comment.