C 中的作用域隐藏 [英] Scope hiding in C

查看:36
本文介绍了C 中的作用域隐藏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C 有作用域隐藏功能吗?

Does C have scope hiding?

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

For example, if I have a global variable:

int x = 3; 

我可以在函数内声明"还是在主另一个"int x 中?

can I 'declare' inside a function or main 'another' int x?

推荐答案

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

Yes, that's how C works. For example:

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
}

这篇关于C 中的作用域隐藏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆