我有一个阵列,
int a[size];
我想将所有数组元素设置为 1
1
因为数组中的某些索引已经设置为,1所以最好使用条件语句检查每个元素,如
for (int index = 0; index < size; index++) { if (a[index] != 1) a[index] = 1; }
或者设置所有索引无论如何.会有什么区别?
c++
c++ ×1