Using a variable with the same name in different spaces

前端 未结 4 727
走了就别回头了
走了就别回头了 2020-12-20 10:51

This code compiles, but I have a run time error in Visual Studio:

Run-time check failure #3 - the variable \'x\' is being used without being initializ

4条回答
  •  星月不相逢
    2020-12-20 11:27

    x is defined at the left of =.

    so in x[x], [x] refer to the global one,

    whereas in x = x;, x hides the global x and initializes from itself -> UB.

提交回复
热议问题