I've made a global variable for an array that's used in two files. We'll call them file1.c and file2.c, the variable is defined in a header file that both of them use, I'll call this file shared.h.
The variable is defined as int items[100];
in shared.h.
The main is in file1.c, and it calls functions from file2.c, the main will first initialize all values in the array with -1.
for(i = 0; i < 100; ++i){
items[i] = -1;
}
Now, when I call a function from file2.c that uses items
, i've noticed that all values in the array are reset to 0 instead of -1.
My question is why is the global variable re-initializing?