1. Replace a=a+1 with a++ and ++a and A+=1, a--and--a instead of a-=1
in general, if a function is defined as an inline function, at the time of program compilation, the compiler will replace each call to the function directly with the code in the body of the function, thus eliminating the call of the function and the corresponding protection field, parameter passing and returning operations, thus speeding up the execution speed of the whole program. In summary, the storage unit. Declaring a reference is not a new definition of a variable, it simply means that the reference name is an alias of the target variable name, it is not a data type in itself, so the reference itself does not account for the storage unit, and the system does not assign a storage unit to the reference. So a reference pass is faster than a non-reference pass.
and reference passing can change the value of a parameter directly, but if you use non-reference delivery, you declare the parameter as a global variable to change its value. (Pointer to Inter reference)
Frequently cited
Constant reference declaration method: Const type identifier & reference name = target variable name; A reference declared in this way cannot be modified by reference to the value of the target variable, thus making the target of the reference a const, which achieves the security of the reference.
4. Reduce Division operations
Whether it is an integer or a floating-point operation, starting will be time-consuming, so the division operation is the equivalent of the multiplication operation. For example: A/b>20 can be changed to a>b*20, which can simplify the running time of the program.
5. Postpone defining local variables
Although the standard in the C language is to define variables uniformly at the beginning, it is best to abandon this practice in C + + because of the unnecessary overhead and time-consuming effort.
Defining an object variable often requires calling a function (constructor). If a variable is required only in certain situations (for example, within an if declaration statement), it is defined only when it is needed, so that the constructor is called only when it is used.
Moreover, delaying the definition of variables will improve the efficiency of the program, enhance the readability of the program, and create better visibility.
6. When initializing a large section of memory, use memset as much as possible, for example, multiple initialization of an array
......
Now update this C + + learning to continue updating as you go further
Common methods of improving program efficiency in C and C + +