What's left in the array if only a part of it is initialized ...

So if I have something like this

int AR[50];
cout<<"Enter the elements of the array : "<<endl;
for(int i = 0 ; i < 5 ; i++)

so in the code I only initialized or gave values for the first five elements, what happens to the rest of it I mean are they null like '\0' or some junk is present there ?
They will be zero-initialized. For example

int AR[50] = { 1, 2 };

AR[0] will be initialized by 1, AR[1] will be initialized by 2 and all other elements will be initialized by 0.

But in your example there is no initialization of the array. You are assigning values to elements of the array after its declarfation. So the other elements will have undefined values.
Last edited on
Topic archived. No new replies allowed.