ProgrammingHardAccenture · Product company OA

What is printed?

What is printed?
int a = 3, b = 0;
int r = (a > b) + (a && b) * 2 + (a || b) * 4 + !b * 8;
printf("%d", r);
  1. A. 5
  2. B. 15
  3. C. 13
  4. D. 14

Correct answer: C. 13

Relational and logical operators give exactly 0 or 1: a > b is 1, a && b is 0, a || b is 1, !b is 1. So r = 1 + 0 + 4 + 8 = 13. '15' assumes a && b is true because a is.

More C Programming questions

Exams that ask this topic