ProgrammingEasyTCS NQT · Infosys pattern

What is printed?

What is printed?
printf("%.2f %d %d", 7 / 2.0, 7 / 2, 7 % 2);
  1. A. 3.50 3 1
  2. B. 3.50 3.5 1
  3. C. 3.00 3 1
  4. D. 3.50 4 1

Correct answer: A. 3.50 3 1

If either operand is floating, division is floating: 7 / 2.0 = 3.5, printed with two decimals as 3.50. Two ints use integer division, which truncates: 7 / 2 = 3. 7 % 2 is the remainder, 1.

More C Programming questions

Exams that ask this topic