# Beginner C++ Questions About Arrays (2 Questions)



## rankbeginner (Jun 24, 2004)

Hello Experts,

*Question 1:*

To initialize the 4 elements of integer array named *numbers* to the value of 0, is THIS

int number [4] = { 0 };

correct, and the exact same thing as saying this:

int number [4] = { 0, 0, 0, 0 }; // ?

*Question 2:*

Assuming 
double x [ 6 ], y [ 14 ];

What C++ statement could I write that would

copy array named *x* into the first part of array named *y*. // ?

Thanks again! ... RB


----------



## Chicon (Jul 29, 2004)

Hi rankbeginner,

I am not an C++ expert but I would do this to answer your questions :

Question 1;

for (int i = 0; i < 4; i++) {
number _ = 0;
}

Question 2

for (int i = 0; i < 6; i++) {
y  = x;
}_


----------



## rankbeginner (Jun 24, 2004)

Thank you. I wish I knew if these were correct. Can anyone confirm this? 
--RB


----------



## coderitr (Oct 12, 2003)

Chicon is correct.


----------



## rankbeginner (Jun 24, 2004)

Thanks Chicon and thanks coderitr.
--RB


----------



## Shadow2531 (Apr 30, 2001)

#1

*int number[4] = {0};* is O.K. to use.

If you only initialize the first element of the array, the rest of the elements will be auto-initialized to zero.

If you don't want it to happen automatically, then use the loop as suggested.


----------

