ProgrammingVery hardProduct company OA

What is printed?

What is printed?
#define SCALE(x) (x * factor)
int factor = 3;
int f(void) { int factor = 10; return SCALE(2); }
int main(void) { printf("%d %d", f(), SCALE(2)); }
  1. A. 6 20
  2. B. 20 6
  3. C. 6 6
  4. D. 20 20

Correct answer: B. 20 6

A macro is pasted as text and its names are looked up where it is used. Inside f, factor means the local 10, giving 20; in main it means the global 3, giving 6. A function would always use the global.

More C Programming questions

Exams that ask this topic