ProgrammingVery hardProduct company OA

What is printed?

What is printed?
#define f(x) ((x) * 2)
int (f)(int x) { return x + 100; }
int main(void) { printf("%d %d", f(1), (f)(1)); }
  1. A. 2 2
  2. B. 101 101
  3. C. 2 101
  4. D. Compilation error

Correct answer: C. 2 101

A function-like macro expands only when its name is directly followed by '('. In (f)(1) and in the definition int (f)(int x), the name is followed by ')', so the real function is defined and called. Plain f(1) is the macro.

More C Programming questions

Exams that ask this topic