我如何在C或C ++全局初始化数组? [英] How can I initialize an array globally in C or C++?
问题描述
我试图做到这一点:
的for(int k = 0; K< context.size(); K ++)
{
cc_no_issue [K] = 0;
}
谁能告诉我我该怎么做,在全球范围?每当我尝试,我得到这些错误:
在供结果预计不合格-ID
k不定义类型搜索
k不定义类型
块引用>解决方案这会做什么:
长cc_no_issue [100] = {0};
这是正确的初始化。
请注意:这将所有内容都初始化为0
这句话:
长cc_no_issue [100] = {1,2};
将设置
cc_no_issue [0]
1cc_no_issue [1]
2,其余为0你可以看到上面的链接了解更多信息。I'm trying to do this:
for(int k=0; k<context.size(); k++) { cc_no_issue[k]=0; }
Can someone tell me how I can do that globally? Whenever I try I get these errors:
expected unqualified-id before "for"
k does not define a type
k does not define a type
解决方案This will do:
long cc_no_issue[100]={0};
And this is the proper initialization.
Note: this will initialize all the contents to 0.
This sentence:
long cc_no_issue[100]={1,2};
will set
cc_no_issue[0]
to 1,cc_no_issue[1]
to 2, and the rest to 0. You could see the link above for more information.这篇关于我如何在C或C ++全局初始化数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!