I was trying to debug my code in another function when I came across this "strange" behavior.
#include <stdio.h> #define MAX 20 int main(void) { int matrix[MAX][MAX] = {{0}}; return 0; }
If I set a breakpoint on the line return 0; , and I look at local variables with Code :: Blocks, the matrix is not completely filled with zeros. The first line is there, but the rest of the array contains only random garbage.
I know that I can do a double for loop to initialize everything manually to zero, but was there not a C standard that was supposed to fill this matrix to zero with the {{0}} initializer?
Perhaps because it was a long day, and I was tired, but I could swear I knew that.
I tried to compile various standards (with the Code :: Blocks compiler in the gcc bundle): -std=c89 , -std=c99 , std=c11 , but this is the same.
Any ideas on what's wrong? Could you explain this to me?
EDIT: I specifically ask about the initializer {{0}} .
I always thought that it will fill all columns and all rows to zero.
EDIT 2: I am particularly concerned about Code::Blocks and its gcc kit. Other comments say that the code runs on different platforms. But why does this not work for me?: /
Thanks.
source share