Thursday, 22 August 2013

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

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

A question was asked in a multiple choice test: What will be the output of
the following program:
#include <stdio.h>
int main(void)
{
int a = 10, b = 5, c = 2;
printf("%d %d %d\n");
return 0;
}
and the choices were various permutations of 10, 5, and 2. For some
reason, it works in Turbo C++, which we use in college. However, it
doesn't when compiled with gcc (which gives a warning when -Wall is
enabled) or clang (which has -Wformat enabled and gives a warning by
default) or in Visual C++. The output is, as expected, garbage values. My
guess is that it has something to do with the fact that either Turbo C++
is 16-bit, and running on 32-bit Windows XP, or that TCC is terrible when
it comes to standards. Any heads up on the exact reason? Thanks

No comments:

Post a Comment