Here's one bug:
void main () {
should be
int main (int argc, char** argv) {
Another bug is in your loop. You write past the end of array a
, and if your compiler placed j
in memory immediately following a
(which based on your question I assume it did), then the out-of-bounds array access will actually end up assigning a value to j
. Hence, when you write 10
into a[10]
(which doesn't exist), you are writing it into the memory where j
lives (causing this to act like j = 10
). However, this behavior is dependent on how your compiler lays out the variables in memory, so you may very well see different behavior if you compiled the same program on a different platform.