samedi 28 mars 2020

Why is an array limited by size, when I can initialize values to indices out of its bounds? [duplicate]

I'm trying to understand the concept of a fixed size in an array. Consider the following array:

int arr[1] = {0};

Now, if I subscript arr by any unsigned value greater than 0, I will get undefined values.

But if I do:

arr[1] = 42;

Now index 1 of arr holds 42. I can keep doing this assignment to any index of arr, making arr hold more than one int, which it was originally defined as.

How is arr having a fixed size if I can keep assigning multiple ints to its indices?

Aucun commentaire:

Enregistrer un commentaire