(I am currently in the cainiao stage ......)
When I create a function today, I want to return a class and an integer. Naturally, I want to use a pointer to return a class, and return to return an integer.
Then my statement is:
Function body:
Int funtion (element * P) {element * A = new element ();...... // Some operations on a p = A; // here, P has the value int num = 0; return num ;}
Call function:
Element * P = NULL; funtion (p); // The returned P is null.
Then, I explained and compiled a simple example as follows:ProgramThen, I understand!
Void funtion (int * A) {A [0] = 5;} int main (INT argc, _ tchar * argv []) {int * B = new int [1]; funtion (B); cout <"* B =" <* B; while (true); Return 0 ;}
Pointers are the same as common parameters. They are all form parameters. They all copy the values of real parameters to the form parameters. The only difference is the nature of the pointer.
When the function parameter is a pointer, the function body uses a passed pointer to operate the object to which the Pointer Points, without changing the value, so that the Pointer Points to other memory.
Just like I made a mistake, when the pointer of the real parameter is originally empty, it is still empty! No matter what operation is performed in the function body or the object to which the Pointer Points, the value of the pointer of the form parameter is changed.