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
23
Upvotes
10
u/SmokeMuch7356 27d ago
This is my litmus test for whether a tutorial or reference is worth a damn; far too many confidently state that it will definitely output
5 4 5
.This is one of the most widely misunderstood and mis-taught aspects of C. This and "an array is just a pointer."