Alf*_*ong 11 c scope global-variables local-variables
例如
#include<stdio.h>
int foo = 100;
int bar()
{
int foo;
/* local foo = global foo, how to implemented? */
return 0;
}
int main()
{
int result = bar();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我认为在功能栏中,直接调用foo将获得全局foo.我怎么能引用当地的foo?我知道在C++中,有这个指针.但是,C有类似的东西吗?
非常感谢!
Dav*_*nan 15
不,通过声明foo
中bar()
,你已经采取了全球性foo
超出范围.bar()
当你引用内部时,foo
你得到局部变量.
归档时间: |
|
查看次数: |
14881 次 |
最近记录: |