array

Aug 25, 2012 at 7:28am
does arr[160]={0}; means each element of the array "arr" has been initialised to 0??
Aug 25, 2012 at 7:30am
no, only the first element=0
Aug 25, 2012 at 7:50am
so how to initialise whole array to zero?
Aug 25, 2012 at 7:53am
closed account (o3hC5Di1)
You need to iterate the entire array:

1
2
3
4
for (int i=0; i<160; i++)  //for loop with counter i
{
    arr[i] = 0;  //every iteration set arr[index number i] to zero
}


All the best,
NwN
Aug 25, 2012 at 12:52pm
@vgoel38

When you first create the array, as in int arr[160] = {0};, then yes, that will initialize that array to 0's. Using any number, will cause arr[0], to be that number, but the rest of the array will be filled with 0's. You can test it out by adding a for loop at the start of your program, and cout the array. Do it without and then, with, the initializing to see the difference.
Last edited on Aug 25, 2012 at 12:56pm
Topic archived. No new replies allowed.