Turbo C++: Why does printf print expected values, when no variables are passed to it?

The code has undefined behaviour.

In Turbo C++, it just so happens that the three variables live at the exact positions on the stack where the missing printf() argument would be. This results in the undefined behaviour manifesting itself by having the “correct” values printed.

However, you can’t reasonably rely on this to be the case. Even the slightest change to your build environment (e.g. different compiler options) could break things in an arbitrarily nasty way.

Leave a Comment