1. Non-reference parameters include common object parameters and pointer object parameters
These parameters are all temporarily allocated a local copy in the stack when calling the function, and then initialized, that is, copying the data passed by the real parameter. The called function does not access the value passed by the real parameter itself, and therefore does not modify the value passed by the real parameter. That is, the operations and changes made by the function to this type of parameter only change the value of the local copy, it does not affect the data passed by real parameters.
The non-reference parameter indicates the local copy of the corresponding real parameter, which also means that both overhead is required. The difference is that the time overhead and storage overhead of the pointer parameter are basically fixed and small, the overhead of common non-pointer objects depends on the object size. Once the function execution ends, the values of these local variables will no longer exist.
Note that for pointer parameters, do not confuse the meaning indicated by the value. The pointer parameter value refers to the address value used to store the address (a local copy of the real parameter address, not the real parameter address itself), rather than the object value referred to by the storage address. It is easier to understand the pointer pointing to the pointer. If you want to operate on a real pointer parameter, you can use a pointer parameter pointing to the pointer. For example, void func (INT ** PTR), you can use & retrieve the pointer address for calling.
2. Reference parameters also include reference parameters pointing to Common Object Reference parameters and pointer reference parameters.
When you have an understanding of the first case, you can refer to references (mainly ownwaterloo) in addition to the descriptions in reference books ).
Many people think that using a reference parameter does not require overhead, and then they feel that using a reference parameter is more efficient than using a pointer parameter. Actually, this is not the case.
In C ++, using reference parameters seems safer and more natural (this is like killing a chicken without a knife). Of course, this is what we say when we know the situation, haha.
Generally, a reference can be implemented, and a pointer can also be implemented. However, a reference may not be allowed if a pointer can be implemented.
Static, inline, and const are not considered above. I think there should be other better ideas and explanations, in fact, I want to discuss that the pointer parameter value of a common function is a local copy passed by a real parameter, which requires overhead, the Operations and changes made to the value do not affect the value passed by the real parameter. (I am afraid that the content indicated by the address will be misunderstood here ); the other one is the difference between the reference form and the pointer form parameter. In fact, I have learned about the differences between the reference and pointer. I checked it. It seems that the usage of the parameter is relatively small.
Turn: http://bbs.chinaunix.net/thread-3562774-1-1.html