Elements initialisation issue

Suppose we initialised an array of size 10 with 0 then this initialises all the elements with 0 but if we initialise the array with say suppose 5 then only first element gets initialised with 5 and rest with zero. Why.

@harshit_03
Because that is how it is programmed in C++. There isn’t much reasoning to it. If you want to do this, you can use fill() or memset.

So that’s a convention. Ok I got it. Thanks

1 Like

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.