I received the following question in an interview:
Given the following code, what is the value of y and what is the value of x at the end of the program?
#define min(a, b) a < b ? a : b
int x = 0;
int y = min(x++, 5);
printf("%d %d\n, x, y);
I understand why x will be 2 at the end of the program, since the preprocessor will replace the macro with:
x++ < 5 ? x++ : 5
And x will be incremented twice, but why is y 1? In my head the increments haven't gone off yet when y receives its new value, so it would be 0. What happens behind the scenes?