Explain the Program Output listed on page 507 Program97 of t
Explain the “Program Output” listed on page 507, Program9-7 of the Starting Out with C++ 8th Edition textbook. How does the pointer notation work with array name?
Solution
Even when you declare an array it is more or less equivalent to declaring a pointer and assiging it a memory. The name of the array is a pointer to the memory. The statement:
a[i] is equivalent to *(a+i). *a represents the first element in the array, so if you would like to access to the (i+1)th element in the array you would go the address a+i and get its value by writing *(a+i) which is same as a[i].
In the program when you say
doublePtr = coins;
coins is a pointer the block of memory assigned to the array. so in the line 21 when you write doublePtr[count], the compiler will look at the same memory place as coins[count], so its the same value.
In line37 when you write *(coins+count), for compiler it is same as coint[count].
