dev c++ - Automatic variable in C not initialized but given fixed value within loop -
i read automatic variables in c, if not initialized values, contain garbage values. however, found did not correspond understanding. consider following piece of code.
#include <stdio.h> main() { int = 0; (i = 0 ; i< 10; i++) { int x; int = 500; printf("%d\t%d\n", a, x); } }
output:
500 2 500 2 500 2 500 2 500 2 500 2 500 2 500 2 500 2 500 2
my question - shouldn't expecting garbage values instead of 2s? ran program on dev-c++ on windows machine.
uninitialized
means declared not set definite known value before used.
it have value, not predictable one.in case 2
. on other system may else.
Comments
Post a Comment