array

does arr[160]={0}; means each element of the array "arr" has been initialised to 0??
no, only the first element=0
so how to initialise whole array to zero?
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
@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
Topic archived. No new replies allowed.