使用非零值初始化Int数组 [英] Initializing Int Array With a Non-Zero Value
问题描述
大家好!
有谁知道如何用非零数字初始化一个int数组?
非常感谢你。
真的是你,Simon Dexter
Hi, Everyone!
Does anyone know how to initialize an int array with a non-zero number?
Thank You Very Much.
Truly Yours, Simon Dexter
推荐答案
< si ****** @ yahoo.com>在消息中写道
news:11 ********************** @ g47g2000cwa.googlegr oups.com
<si******@yahoo.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com
大家好!
有谁知道如何初始化一个非零数字的int数组?
非常感谢你。
真的是你,Simon Dexter
Hi, Everyone!
Does anyone know how to initialize an int array with a non-zero
number?
Thank You Very Much.
Truly Yours, Simon Dexter
Int不是int。 C ++区分大小写。
在声明时执行此操作的唯一方法是根据需要重复数字
,例如,
int array [5] = {9,9,9,9,9};
另外,你可以在声明后的一个循环。
向量允许你避免重复这个数字:
std :: vector< int>数组(5,9);
-
John Carson
Int is not int. C++ is case sensitive.
The only way to do this at the point of declaration is to repeat the number
as many times as you need it, e.g.,
int array[5] = {9,9,9,9,9};
Alternatively, you can do it in a loop after the declaration.
Vectors allow you to avoid repeating the number:
std::vector<int> array(5, 9);
--
John Carson
2005年7月12日21:46:19 -0700, si******@yahoo.com 勇敢地做了
avow:
On 12 Jul 2005 21:46:19 -0700, si******@yahoo.com did courageously
avow:
大家好!
有谁知道如何用非零数字初始化一个int数组?
int intArr [n1] = {x1}; //声明和初始化
n1可以是任何正整数值,x1可以是任何合法的
值; number,char,指向另一个数组的指针等等。我相信你不需要指定列表中的所有元素。
不需要指定列表中的所有元素。那就是说,我相信,如果我错了,我会得到纠正
- 或 -
int intArr [n1]; //声明
intArr [0] = x1; //初始化
这一切都取决于你想走多远。如果需要,你可以在第一个例子中给它一个完整的
列表。或者,您可以使用for循环
运行数组索引,直到它填充最后一个
元素,使用循环内的第二个语句替换您的
索引变量为零并应用你需要的任何数字
应用程序感觉适合阵列。
非常感谢。
Hi, Everyone!
Does anyone know how to initialize an int array with a non-zero number?
int intArr[n1] = {x1}; // declaration and initialization
n1 can be any positive integer value and x1 can be any legitimate
value; number, char, pointer to another array, etc.. I believe you
don''t need to specify all the elements in the list. That said, I
trust I will be corrected if I''m wrong
-- OR --
int intArr[n1]; // declaration
intArr[0] = x1; // initialization
It all depends on how far you want to go. You can give it a completer
list in the first example if you want. Or, you can use a for loop
that runs through the array index until it has filled the last
element, using the second statement inside the loop, substituting your
index variable for the zero and applying whatever number you
application feels is appropriate for the array.
Thank You Very Much.
欢迎您。
Ken Wilson
阿梅尔。 DLX。 Tele,Gary Moore LP,LP DC Classic w / P90s,
Jeff Beck Strat,Morgan OM Acoustic,
Rick 360/12,Std。 Strat(MIM),Mesa 100 Nomad,
Mesa F-30
You''re welcome.
Ken Wilson
Amer. Dlx. Tele, Gary Moore LP, LP DC Classic w/P90s,
Jeff Beck Strat, Morgan OM Acoustic,
Rick 360/12, Std. Strat (MIM), Mesa 100 Nomad,
Mesa F-30
"Goodnight Austin, Texas, wherever you are."
" Rick N. Backer" <柯******** @ NsOhSaPw.cAaM>在消息中写道
新闻:如果******************************** @ 4ax.com
"Rick N. Backer" <ke********@NsOhSaPw.cAaM> wrote in message
news:if********************************@4ax.com
2005年7月12日21:46:19 -0700, si ****** @ yahoo。 com 勇敢地说:
On 12 Jul 2005 21:46:19 -0700, si******@yahoo.com did courageously
avow:
大家好!每个人都有!
有谁知道如何用非初始化int数组零号码?
Hi, Everyone!
Does anyone know how to initialize an int array with a non-zero
number?
int intArr [n1] = {x1}; //声明和初始化
n1可以是任何正整数值,x1可以是任何合法的值; number,char,指向另一个数组的指针等。我相信你不需要指定列表中的所有元素。那就是说,我相信如果我错了我会得到纠正
int intArr[n1] = {x1}; // declaration and initialization
n1 can be any positive integer value and x1 can be any legitimate
value; number, char, pointer to another array, etc.. I believe you
don''t need to specify all the elements in the list. That said, I
trust I will be corrected if I''m wrong
您的代码具有初始化数组的第一个元素的效果
x1,其余为零。没有演员也不能使用指针值。
-
John Carson
Your code has the effect of initializing the first element of the array to
x1 and the rest to zero. You also can''t use pointer values without a cast.
--
John Carson
这篇关于使用非零值初始化Int数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!