What is the difference Between those types of initializing An array called "IntegerArray" With 5 element :

int IntegerArray[5] = {0};
     int IntegerArray[5] = {0,0,0,0,0};
     int IntegerArray[5] = {10,20,30,40,50};
     int IntegerArray[]  = {10,20,30,40,50};

Please i need an obvious explanation for each line as i am confused.....

Thanks for reading...............

1.) Every element is assigned the value zero
2.) Accomplishes the same thing
3.) No different than 2.)
4.) Since you are defining the array you don't need to tell the compiler how big it is

Just to repeat whats been said again.

int IntegerArray[5] = {0};
initializes all elements inside the array to 0.

int IntegerArray[5] = {0,0,0,0,0};
Here you are explicitly initializing each element to 0.

int IntegerArray[5] = {10,20,30,40,50};
Here you are explicitly giving each element inside the array a value.
So IntegerArray[0] has 10 stored, IntegerArray[1] has 20, and so on.

int IntegerArray[] = {10,20,30,40,50};
Here noticed that there is no 5 like before. By putting no number, and just using the
array brackets,[], you tell the compiler that the size of the array is the number
of elements inside the array. Since this "{10,20,30,40,50" has 5 element, the compiler deduces that IntegerArray has 5 elements.

Thanks jonsca,firstPerson ..... That was Helpful

firstPerson, you explain good, i hope better for you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.