in Programming in C edited by
361 views
7 votes
7 votes

What will be the output of this program ?

#define square(x) x*x
main()
{
int z;
z = 25/square(5);
printf("%d",z);
}
in Programming in C edited by
by
361 views

2 Answers

9 votes
9 votes
Best answer
Explanation:
the macro call square(5) will substituted by 5*5 so the expression becomes z = 25/5*5 . Since / and * has equal priority the expression will be evaluated as (25/5)*5 i.e. 5*5 = 25
selected by

2 Comments

woah woah food for thought!!!
3
3
So, square(5) would not return the value of the expression, but the expression itself.

And then since / and * have equal priorities, left associativity would come into play. So, 25.

 

LOVED this question!
1
1
0 votes
0 votes

The output of the program is 3.

Explanation:

Initially, a is assigned the value 0.

Since there's no case label matching a, the control jumps to default, where a is assigned 4.

Then, it goes to case 6, where a is decremented by 1 (a becomes 3).

Next, it goes to case 5, where a is incremented by 1 (a becomes 4).

Finally, it goes to case 1, where a is decremented by 1 (a becomes 3).

The value of a is printed, which is 3.

Answer:

Related questions