C++: Uninitialized variables garbage

前端 未结 5 1044
攒了一身酷
攒了一身酷 2020-12-12 02:38
int myInt;
cout << myInt; // Garbage like 429948, etc

If I output and/or work with uninitialized variables in C++, what are their assumed val

5条回答
  •  無奈伤痛
    2020-12-12 03:26

    It's not even guaranteed to be a value at all. Trying to read the int, anything can happen (such as a signal sent causing your program to terminate). With particular importance in real life programming, switching on a not initialized bool can cause you hit neither true nor false cases.

提交回复
热议问题