+ 1
Here, amount and amount+6 alone act as pointers that store the memory address of amount[] and sixth memory address after amount[] respectively. In C++, arrays are stored with addresses the same as their first element. Hence amount points to address of amount[0]. Next, the address of each subsequent element is the subsequent address in memory. Their memory address differ by the size of each element, in this case, 4 bytes for float. Hence, amount+i points to amount[i] for 0 <= i < 10 as only 10 values of i, 0 to 9, are for which amount[i] is within its size. Furthermore values of i lead to amount+i pointing to addresses the array did not hold. These were never declared nor defined, so they got assigned a garbage value. In the end, amount is the pointer to amount[0] and amount+6 is the pointer to amount[6]. See the attached code. https://code.sololearn.com/cwl0vEB4ipUx/?ref=app
3rd Dec 2019, 3:17 AM
Naveen Maurya
Naveen Maurya - avatar