【发布时间】:2010-03-08 17:44:20
【问题描述】:
我总是对静态变量以及它们的内存分配方式感到困惑。
例如:
int a = 1;
const int b = 2;
static const int c = 3;
int foo(int &arg){
arg++;
return arg;
}
a、b 和c 的内存是如何分配的?
如果我调用foo(a)、foo(b) 和foo(c),有什么区别(在内存方面)?
【问题讨论】:
-
你不能打电话给
foo(b)或foo(c)。 -
也许值得知道的是,在 C++ 中,
b和c都具有静态链接。在 C 中,b具有外部链接。
标签: c++ c memory static memory-management