0
what is the problem of this snippet code and why this is like that!? i think the stack overflows here but somone says its '0'.
https://code.sololearn.com/cW5dBl45S9RY #include<iostream> int main(){ int a[10],i; for( i=4;i<9;i+=3) {a[i]=i-2;} std::cout<<a[8]; }
4 odpowiedzi
+ 4
The problem is that the array is not initialised. Only a[4] and a[7] are set. For a[8], any value is possible, since memory space does not get leared for local arrays.
+ 3
ok Ani Jona 🕊 you mean the value would be change each time one compile the code?
+ 1
Not exactly each compile but each run of the program (if you wouldn’t compile before each run)
0
You're right. I misunderstood it to mean one compilation, change each run. But i guess it means each time the code is compiled.
No. Opposed to static or global arrays, there is no information about the array content compiled into the code. The content is whatever was left in the memory area your program is mapped to upon start. And that may change each time it is run.