I'm new to c++ and I've read that arrays are fixed sized. So I'm confused with the following.
int a[] = {0};
a[1] = 1;
a[2] = 2;
a[3] = 3;
//.....
The array could be populated like this many times in a loop. So how is it fixed sized?
Edit: Understood that it's undefined behaviour from the comments. It is fixed size but the compiler doesn't throw errors (which is what confused me) even if the limit is exceeded and the program is compiled.
Answer
The array in you example is of fixed size (1 element), but it doesn't perform bounds check when assigning new data via subscript, so what you do here is assigning values to memory your array doesn't own, which is undefined behavior.
Comments
Post a Comment