相关疑难解决方法(0)

如何引用局部变量在C中共享全局变量的同名?

例如

#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有类似的东西吗?

非常感谢!

c scope global-variables local-variables

11
推荐指数
1
解决办法
1万
查看次数

标签 统计

c ×1

global-variables ×1

local-variables ×1

scope ×1