ProgrammingHardTCS NQT · Infosys

int x = 0; if (x = 5) printf("y"); else printf("n"); What is printed?

  1. A. nothing
  2. B. y
  3. C. compile error
  4. D. undefined

Correct answer: B. y

x = 5 assigns 5 to x and yields 5, which is nonzero, so the condition is true. The program prints y, a classic slip for == is still valid C.

More C Programming questions

Exams that ask this topic