12

例如

#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;
}

我认为在函数栏中,直接调用 foo 只会得到全局 foo。我如何参考当地的 foo?我知道在 C++ 中有这个指针。但是,C 有类似的东西吗?

非常感谢!

4

1 回答 1

16

不,通过声明fooin bar(),您已将全局foo超出范围。bar()当您引用内部时,您将foo获得局部变量。

于 2011-04-29T03:16:24.887 回答