1. Pointers to arrays
int balance[ }; int *//ptr is a pointer to the array balance // or it is also possible: ptr = &balance[];
The difference between balance and PTR is that PTR is a variable and balance is a constant:
// This is not possible, the IDE will error that the expression must be a modifiable lvalue
2. Pointer as function return value
According to rookie tutorial: http://www.runoob.com/cplusplus/cpp-return-pointer-from-functions.html
"C + + does not support the return of the address of a local variable outside of a function unless the local variable is defined as a static variable"
Chestnuts originally used random number generation, feel the time to see chaos, directly changed to 1~10 increment, long like this:
// function to generate and return a random number int * getrandom () { staticint r[]; for (int0; + +i) { = i; << R[i] << endl; } return R;}
In fact, it is well understood that if the variable is not defined as static, the variable in the function is a local variable, the function is called when the local variables allocated memory space, the function returned after the allocated space has been recycled by the operating system.
If the static modifier is removed, the output is garbled, but it can be defined as a global variable:
C + + Learning Note (ii)-pointers