In C++, objects of scalar types are not zero-initialized. They are default-initialized, which means the value they get at initialization is undefined.
In particular, the value is unlikely to be 0 for char
s, int
, etc., and definitely you shouldn't rely on it to have any particular value. If you want your array cells to be initialized to 0 before you start working with them, you have to initialize them manually.
If you come from a Java world, you might think this is an unnecessary bulk of work, but consider that you're working with C-style arrays, and C is not meant to sacrifice performance for programmer time. There are cases where an initialization to 0 would uselessly waste CPU time, and you don't want to pay for what you don't use.