:: 一元作用域解析运算符,局部变量与全局变量同名时,可以用来访问全局变量。

#include<iostream>
using namespace std;

int i{ 10 };
int main()
{
    int i{ 11 };
    cout << i << endl; //11
    cout << ::i << endl; //10

    return 0;
}

 

相关文章:

  • 2022-12-23
  • 2021-12-26
  • 2021-07-28
  • 2022-12-23
  • 2021-05-01
  • 2021-11-17
  • 2021-11-14
  • 2021-05-10
猜你喜欢
  • 2021-08-08
  • 2022-01-28
  • 2022-12-23
  • 2022-12-23
  • 2021-12-06
  • 2021-05-11
相关资源
相似解决方案