On the other hand, if an array is to hold integers of type
int
, most implementations of C++ would allocate
4 bytes per integer:
0 1 2 <-- Array | | | index v v v --------------- --------------- --------------- --*---*---*---*---*---*---*---*---*---*---*---*---*- | | | | | | | | | | | | | -*---*---*---*---*---*---*---*---*---*---*---*---*-- ^ ^ ^ ^ ^ ^ | | | | | | 88 90 92 94 96 98
In this example, the first element in the array appears at memory address 88, the second appears at 92, and the third appears at 96.