Question 57 What would be the output of the following program?
Qualcomm technical mcq question, verified with a worked answer. Free to practise - no sign-up.
Question 57
What would be the output of the following program?
#include <stdio.h>
#define PRINTF(int) printf("%d", int)
int main()
{
int x = 2, y = 3, z = 4;
PRINTF(x);
PRINTF(y);
PRINTF(z);
return 0;
}
**MCQ
Show answer & explanation
The macro PRINTF(int) expands to printf("%d", int) where the parameter name int is replaced by the actual argument. When called as PRINTF(x), PRINTF(y), and PRINTF(z), they expand to printf("%d", x), printf("%d", y), and printf("%d", z) respectively, printing the values 2, 3, and 4 sequentially without spaces, resulting in "234". The parameter name int being a keyword does not cause a compile error because it's only a macro parameter name, not declared as a variable.
Step-by-step Derivation:
Step 1: Preprocessor substitution occurs before compilation.
Step 2: PRINTF(x) → printf("%d", x) → prints 2
Step 3: PRINTF(y) → printf("%d", y) → prints 3
Step 4: PRINTF(z) → printf("%d", z) → prints 4
Step 5: Output concatenated: 234