Point of declaration in C++

前端 未结 3 1072
盖世英雄少女心
盖世英雄少女心 2020-12-03 04:36

Why isn\'t the output 101 while I assigned the previous x to the new x?

int x = 101;
{
    int x = x;
    std::cout &l         


        
3条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-03 05:17

    variable scope In front of x will be overwritten. int x = x; This one there are two processes. One: int x;(define variable x and allocate memory and specify the initial value : x = 0); this moment , the front x will be hidden. Two: x = x;(Do not find the value x);

提交回复
热议问题