范围隐藏在C中

Bel*_*lgi 4 c scope

C是否隐藏了范围?

例如,如果我有一个全局变量:

int x = 3; 
Run Code Online (Sandbox Code Playgroud)

我可以'声明'在函数内部或主要'另一个'int x吗?

Adi*_*ann 5

是的,这就是C的工作方式.例如:

int x;

void my_function(int x){ // this is another x, not the same one
}

void my_function2(){
  int x; //this is also another x
  {
    int x; // this is yet another x
  }
}
int main(){
  char x[5]; // another x, with a different type
}
Run Code Online (Sandbox Code Playgroud)