ProgrammingHardTCS NQT · Accenture

What is printed?

What is printed?
#include <stdio.h>
int main(void) {
    printf("%d", (int)(7 / 2 * 2.0));
}
  1. A. 7
  2. B. 6
  3. C. 3
  4. D. 4

Correct answer: B. 6

7 / 2 is integer division giving 3, and 3 * 2.0 = 6.0, which the cast turns into 6.

More C Programming questions

Exams that ask this topic