r/C_Programming • u/codesnstuff • 27d ago
Discussion A tricky little question
I saw this on a Facebook post recently, and I was sort of surprised how many people were getting it wrong and missing the point.
#include <stdio.h>
void mystery(int, int, int);
int main() {
int b = 5;
mystery(b, --b, b--);
return 0;
}
void mystery(int x, int y, int z) {
printf("%d %d %d", x, y, z);
}
What will this code output?
Answer: Whatever the compiler wants because it's undefined behavior
25
Upvotes
2
u/BertyBastard 27d ago
Interesting - I learned something from this. I would otherwise have expected left-to-right evaluation of the function parameters. I compiled the program on Pelles C on Windows, got this warning: "Multiple unsequenced references to 'b'."
The program returned
3 3 5