Please help, why 10? | SoloLearn: Learn to code for FREE!

+4

Please help, why 10?

#define prod(i, j) i * j int main() { int x = 3, y = 4; print("%d", prod(x + 2, y - 1)); return 0; }

c

6/7/2020 3:47:42 AM

Mofey

3 Answers

New Answer

+9

Here operation in printf() executed as: prod(x+2,y-1) prod(3+2*4-1) prod(3+8-1) prod(3+7) prod(10) In this way output is 10

+2

The Crazy Programmer Thank you Wow, I didn't see that coming

+1

It happens because multiplication has higher precedence than sum. It is often tricky using preprocessor functions