From what I understand, uninitialized array in C means garbage value at memory allocated for the array. But when i experiment with that. So, I tried this.
#include <stdio.h>
int main (){
int j[10];
for(int k = 0; k < 10;k++){
printf("j[%d]:%d\n",k,j[k]);
}
}
Here is the output:
j[0]:0
j[1]:0
j[2]:0
j[3]:0
j[4]:0
j[5]:0
j[6]:0
j[7]:0
j[8]:0
j[9]:0
I assume clang just fixed by putting default value into them. I'm using Apple clang version 12.0.5 (clang-1205.0.22.11) running on M1 MacBook Air. Now here is the confusing part:
#include <stdio.h>
int main (){
int i =10;
int j[i];
for(int k = 0; k < 10;k++){
printf("j[%d]:%d\n",k,j[k]);
}
}
Here is what i have got: First run
j[0]:13172736
j[1]:1
j[2]:13172736
j[3]:1
j[4]:0
j[5]:0
j[6]:1865774432
j[7]:1
j[8]:48
j[9]:0
Second run
j[0]:72499200
j[1]:1
j[2]:72499200
j[3]:1
j[4]:0
j[5]:0
j[6]:1806906720
j[7]:1
j[8]:48
j[9]:0
Third run.
j[0]:8912896
j[1]:1
j[2]:8912896
j[3]:1
j[4]:0
j[5]:0
j[6]:1870689632
j[7]:1
j[8]:48
j[9]:0
Fourth:
j[0]:15417344
j[1]:1
j[2]:15417344
j[3]:1
j[4]:0
j[5]:0
j[6]:1863988576
j[7]:1
j[8]:48
j[9]:0
There seems to be some pattern here, and its pretty consistent, where does this comes from?