LearnFrenzy
Sign in Take a free test

Operators and Expressions · Predict the Output · Question 11

n /= 4 then n *= 4 – output Answer, explanation & discussion

  • Output
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 11 Back to Exercise

What is the output of the following C program?

main.c
#include <stdio.h>

int main(void) {
    int n = 10;
    n /= 4;
    n *= 4;
    printf("%d\n", n);
    return 0;
}
  • A 8 Correct
  • B 10
  • C 12
  • D 2
Correct Answer: Option A

10 / 4 is 2 in integer division, and 2 × 4 = 8. Dividing first loses information; multiply first when the result must be exact (watching for overflow).

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links