C++: Uninitialized variables garbage

前端 未结 5 1054
攒了一身酷
攒了一身酷 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:19

    Program A is closed, it had an int with the value 1234 at 0x1234 -> I run my program, myInt gets the address 0x1234...

    Note also that because of virtual memory in modern operating system what Program A called address 0x1234 is unlikely to actually refer to the same space in physical memory as what your program calls address 0x1234.

提交回复
热议问题