我意识到它在超出范围后保留了价值(但变得无法访问),但我有几个问题.
当人们说它在范围之外无法访问时,它只是意味着你不能在其识别范围之外改变价值(它会出错)吗?
我在考虑这段代码:
#include "iostream"
void staticExample();
int main()
{
staticExample();
return 0;
}
void staticExample()
{
for (int i = 1; i <= 10; ++i)
{
static int number = 1;
std::cout << number << "\n";
++number;
}
}
Run Code Online (Sandbox Code Playgroud)我想,在循环的每次迭代中,我将'number'变量设置为1.正如我第一次预期的那样,它打印了1,2,3 .. 10.编译器是否识别出行设置它是1是一个声明而忽略了它的"变化"?
该对象生命一次,因此它被初始化一次。初始化不是赋值。(IINA?\xe3\x81\x84\xe3\x81\x84\xe3\x80\x81\xe3\x81\xaa\xef\xbc\x81)
\n