A silly doubt

Revision en1, by anni11, 2016-12-13 14:06:48

Hello friends, although this is a silly doubt but i have faced some problems because of this.

I have seen that many coders when they code their solutions ,they use the arrays they have declared without initializing it with zero i.e. they write code as if the array already contains zero at all indices while i initialize it with zero, so my doubt is that when we declare a 1-D array or 2-D array or any N-D array then is it automatically initialized with zero at all locations or some random values. And is it always true in all the online judges or do we need to initialize it with zero to eliminate the random values ? For eg when i write the following :

int a[10];

for(int i = 0; i < 10; ++i) cout << a[i] << endl;

I get random values and sometimes zero. Could anyone tell me what is exactly happening. Thanks.

Tags doubt, array, help

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English anni11 2016-12-13 14:06:48 843 Initial revision (published)