Multiple choice technology programming languages

1)#define f(g,g2) g# #g2 main() { int var12 = 100; printf(“%d”,f(var,12)); }

  1. junk value

  2. 100

  3. 12

  4. none of these

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

The macro f(g,g2) is defined as g##g2 (token concatenation using ## operator). When called as f(var,12), it concatenates 'var' and '12' to produce 'var12'. The printf becomes printf('%d', var12). Since var12 is declared as int var12=100, it outputs 100. The ## operator performs token pasting during preprocessing, not string concatenation.

AI explanation

This tests the C preprocessor token-pasting operator (##, likely garbled to '# #' by encoding). The macro is #define f(g,g2) g##g2, so f(var,12) expands via token concatenation to var12 — a real identifier already declared as int var12 = 100. So printf("%d", f(var,12)) becomes printf("%d", var12), printing 100. The token-paste happens at preprocessing time before compilation, merging the literal tokens 'var' and '12' into the single identifier 'var12', not performing any arithmetic or string concatenation.