The first second question is relatively simple, the third problem is good, is a recursive, but the time of the transfer of a problem, I made a flag to mark, but the function changed flag, but after the exit function, flag does not change, think up, it should be no incoming pointer, therefore, to learn.
http://blog.csdn.net/herecles/article/details/6072523
In C + +, if the type of the argument of a function is a data type with a large data type, this is a great inconvenience if you use a generic parameter, which is helpful if you can pass an address or a reference to the original parameter to improve performance.
This paper studies the differences and relations between reference and pointer parameters. In fact, reference and pointer parameters can be used to modify the source data within the bar function, which is common, but they are also different. Here is an example:
[CPP]View Plain Copy
- #include <iostream>
- using namespace Std;
- void Swapbypoint (int* x,int* y); Declaration of Pointer Pass function
- void swapbyreference (int &x,int &y); Declaration of a reference parameter function
- int main ()
- {
- int x = 3;
- int y = 5;
- cout<< "before conversion: x=" <<x<< "y=" <<y<< "/n";
- Swapbypoint (&x,&y); If Swapbypoint (x, y) is used here, the error is: cannot convert parameter 1 from ' int ' to ' int * '
- cout<< "pointer transfer after conversion: x=" <<x<< "y=" <<y<< "/n";
- Swapbyreference (x, y); If Swapbyreference (&x,&y) is used here, the error cannot convert parameter 1 from ' int * ' to ' int & '
- cout<< "referring to a parameter call after conversion: x=" <<x<< "y=" <<y<< "/n";
- System ("pause");
- return 0;
- }
- /* Swap function use pointer to pass the parameter */
- void Swapbypoint (int *x,int *y)
- {
- int temp = *x;
- *x = *y;
- *y = temp;
- }
- /*
- Use reference to pass a parameter
- */
- void swapbyreference (int &x,int &y)
- {
- int temp = x;
- x = y;
- y = temp;
- }
The effect of pointer and reference parameters is the same.
Their differences personally believe that:
- The pointer parameter passes the address of an argument (here is an int argument) so that, although the arguments are different from the formal parameters, they only want the same address, so the operation of the number of the same address affects the original number.
- The reference pass is a parameter itself, but in the calling function, the value of the address that holds them is exchanged.
The invocation of the two methods must be the above, otherwise it will error, in the corresponding code is prompted .....
The problem about function parameter modification of Huawei Machine test summary