Multiple choice technology programming languages

1)#define square(x) x*xmain(){ int i; i=64/square(4); printf(“%d”,i);}

  1. 32

  2. 4

  3. 64

  4. 16

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

The macro square(x) expands to x*x. When used in 64/square(4), this becomes 64/4*4 due to macro expansion (not 64/(4*4)). Following C's left-to-right evaluation for same-precedence operators: 64/4 = 16, then 16*4 = 64. This is a classic macro pitfall - always use parentheses in macro definitions. Option C (64) is correct.

AI explanation

This is the classic macro-expansion trap: #define square(x) x*x performs simple textual substitution without parentheses, so square(4) expands to 4*4, not a single evaluated value. The expression 64/square(4) therefore becomes 64/4*4, and since / and * have equal precedence and are evaluated left-to-right, that's (64/4)*4 = 16*4 = 64. This is why macros should always wrap arguments (and the whole expansion) in parentheses — without that, the result is not the mathematically expected 4.