-4

is there a possibility that a variable which is not appointed a number be appointed negative number by compiler?

I use Dev C++ and it prints "0", but what about other compilers?

Example:

int x;
printf("%d", x);

Dev C++ output: 0

naber2
  • 49
  • 7
  • 3
    You're invoking undefined behaviour by accessing an uninitialized variable, anything can happen; so yes, it is a possibility. – flau Aug 05 '16 at 08:49

1 Answers1

1

Not initializing your variable is undefined behavior under any compiler.

So yes, you could have positive, negative number, or zero.

blue112
  • 52,634
  • 3
  • 45
  • 54
  • "Undefined behaviour under any compiler"? It's undefined behaviour under the standard, and any normal compiler implicitly defines the behaviour (as whatever that compiler makes the program do). – user253751 Aug 05 '16 at 09:23