ProgrammingHardHCL · Tech Mahindra pattern

What is printed?

What is printed?
#define FOO 10
#define BAR FOO + 5
int main(void) {
    int x = BAR * 2;
    printf("%d", x);
}
  1. A. 30
  2. B. 20
  3. C. 15
  4. D. 25

Correct answer: B. 20

BAR expands to FOO + 5, which itself expands to 10 + 5. So BAR * 2 expands fully to 10 + 5 * 2 = 10 + 10 = 20, since * binds tighter than the unparenthesized + inside BAR's expansion.

More C Programming questions

Exams that ask this topic