Do I need to store a value into an array before I loop through it? It works correctly without storing a value, but which one is the “right” way?
int ary3[1000000] = {};
//int ary3[100000] = {0}; //or should I store a value first
for (int i = 0; i < sizeof(ary3) / sizeof(int); i++) {
printf("%d = %d\n", i, ary3[i]);
}
I’ve made a correction. I don’t want to store any values first. I just want to display out the indices immediately after declaration.
It is not okay to not initialize an array unless you are somehow keeping track of which indexes are initialized and which are not. The reason is that you will access some garbage or memory that you are not allowed access to. Also, if other programmers where to start where you left off, they might get some weird results.
Also, avoid magic numbers.