I'm wondering what the array subscripting operator ([]
) do to objects
From this question and this question, I learnt that the []
operator takes an address of an object, adds whatever it is in between the brackets to the object and finally dereferences the sum to obtain an address. However, in array declarations, eg.
int iarr[] = {1,2};
int iarr2[2] = {1,2};
The []
operator doesn't seem to be adding the value in the brackets to the operand, especially in the second example. Instead, it seems to be giving the object the ability to store arrays.
Also, my wild guess is that in int arr2[2] = {1,2}
, arr[2]
will allocate memory for two int
s. Is that true?
As a summary:
What does the []
operator do to its operand during declaration? Does it just give the object the ability to store arrays or does it allocated memory for the array instead?