+ 1

16 is the output of following code. Explain

#include<stdio.h> #define square (a) a*a void main() { int i=16/square(4) ; prints("%d", i) ; }

28th Apr 2020, 3:07 AM
Ravindra Raghuwanshi
1 Odpowiedź
+ 1
coffeeunderrun suggested a good and necessary correction to the macro. More parentheses would be needed if you should call it with an expression like square(i+3). That would incorrectly expand to (i+3*i+3). It should be ((i+3)*(i+3)). Here is a better definition: #define square(a) ((a)*(a))
28th Apr 2020, 6:30 AM
Brian
Brian - avatar