Is using an invalid pointer value legal in C?

后端 未结 3 776
长发绾君心
长发绾君心 2021-01-14 19:59

The following code is undefined behavior in C++ (although it will work okay on almost any widely used implementation):

int* pointer; //uninitialized - likely         


        
3条回答
  •  无人共我
    2021-01-14 20:41

    Not legal. Code like this will compile, but with warnings. Don't ignore them. Don't write code like this. It can affect your system in many not so nice ways. My university teacher once told us he managed to erase one machine's BIOS using code with undefined behaviour.

提交回复
热议问题