Point of declaration in C++

前端 未结 3 966
盖世英雄少女心
盖世英雄少女心 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 04:59

    There's another way to do it.

    #include 
    int x = 101;
    int main()
    {
      int x = ::x;
      std::cout << x << std::endl;
      std::cin.get();
    }
    

提交回复
热议问题