What will be the output of the program?
#include <stdio.h>
#define SQUARE(x) x*x
int main()
{
float s=10, u=30, t=2, a;
a = 2*(s-u*t)/SQUARE(t);
printf("Result = %f", a);
return 0;
}
Answer: A
Correct answer: Result = -100.000000
The unparenthesised macro turns the expression into
a = 2*(s-u*t)/t*t;
and with / and * at equal precedence, left to right:
So -100.000000, not the intended \(-100/4 = -25\).
Please log in or register to report this question.