1. C ++ series functions,
Reference: http://www.cplusplus.com/doc/tutorial/functions/
Value Transfer and reference Transfer
- Value Transfer refers to the parameter passed by the function, which is a specific value (number, String, etc.). When the function body operates these valuesNoChange these parameter values.
- Reference transfer refers to the parameter passed by the function as a variable, and "variable" can be changed, so the function body operates on these variables at the same time.YesChange it.
- What can be solved by reference transfer? When the parameters to be passed take up a lot of space, the efficiency will be very low if the value transfer method is adopted. For example, I uploaded a file of more than 10 GB to the function for processing, because it needs to copy these files to the function, the speed is very slow, but the reference transmission method can solve this problem, because only the variable name is passed.
- What if I want to pass the parameter via reference but do not want the function to change the value of the parameter? Just change it to a constant reference. Add the const keyword before each parameter type that you do not want to change, such as void duplicate (const int & a, const int & B, const int & c)
Inline functions
- Inline functions are mainly used to solve the problem of function calling efficiency and save the overhead of function calling at the cost of space. It can be understood that inline functions are small functions, generally, these functions do not have loops or conditional statements, which can replace macro definitions in C.
- You can add the keyword inline before the function declaration.