If a char
array is uninitialized, are all the array elements automatically initialized as 0
?
I was solving the problem Holes and my first solution which got WA was this : http://ideone.com/Ix4kc9
I then checked someone else's solution which was almost identical but instead of for (z = 0; c[z] != '0'; ++z)
, he had used for (z = 0; c[z] != '\0'; ++z)
. After some googling I found that \0
is NULL character. I don't understand what it actually is. Then I found this question on SO. The top answer says that all uninitialized elements are stored as zeroes. Then why replacing for (z = 0; c[z] != '0'; ++z)
with for (z = 0; c[z] != '\0'; ++z)
gave me an AC?