Uninitialized variable in C [duplicate]

Reading the value of an uninitialized variable leads to undefined behavior. And undefined behavior means that it can crash. It doesn’t mean it will or it is obliged to crash.

An uninitialized variable has unspecified value – it’s just unknown what its value is. So in practice, with any sane implementation, this kind of code will presumably never crash. There’s a valid memory address backing the variable, it has some garbage content, printf() reads it without problem, interprets it as an integer and prints it, that’s all.

Leave a Comment