Your array is zero-initialized "for the first testcase" simply because it is declared with static storage duration. And such array with static storage duration begins its life zero-initialized.
Your
a[100][100]={0};
line has nothing to with it. This is actually a mere a[100][100] = 0
, which is writing a single 0
into a non-existing (out of bounds) element of your array. (The behavior is undefined).
If you wan to reinitialize your array with zeros on each iteration, you have to do it either manually or using a library-level solution, since there is no core-language-level feature that would do it for you. In your case (an array of integers) you can even use the old-fashioned
std::memset(a, 0, sizeof a);
You can also use something clever-but-inefficient like
decltype(a) zeros{};
std::swap(a, zeros);
on each iteration, but it's probably not worth it.