What's the difference between an 'empty' list (ar[5]={} )and 'no-list-at-all' (ar[5]) in array initialisation in C++?

61 Views Asked by At

I'm just a beginner in C++. In my textbook it is stated that, "if the number of initial values is less than the size of the array, they will be stored in the elements starting from the first position and the remaining positions will be initialised with zero, in case of numeric data types." So I was just curious about the below two situations and was confused about the results:

1.

int num[5]={};
for(i=0;i<5;++i)
cout<<num[i]; //result: '00000'
int num[5];
for(i=0;i<5;++i)
cout<<num[i]; //result: some garbage values

In both the above cases, I didn't input any values to the elements (or I hope so). But why the second case didn't print zeros though?

0

There are 0 best solutions below