This is my own summary at this stage, I hope you will add:
First say static:
It represents a static
So 1, hidden, global variables or global functions plus static are inaccessible to other files, only in the current file
2, keep the contents of the variable persisted, because the static variable is stored in the global zone once initialized to know that the program ends the menu user is released
3, the default initialization variable value is 0
4. When defining a member variable or member function with static, it becomes a member of the class, all objects are shared
The role of the const keyword
1. The modifier variable const int A=10,A is a constant that is initialized once at the time of declaration and cannot be assigned in the future.
2, modifier pointers are divided into constant pointers, and pointer constants
A constant pointer is a pointer to a constant, and the pointer must be a constant const int * p
Pointer constant, the content of the pointer is constant, that is, the pointer cannot change int *const P
3, modify the reference. Make a reference a regular drink, you cannot modify the value of a variable by reference
4, modify the array. Array becomes Changshu group, cannot modify the value of the element inside, can only access
5, modifier function parameters. Increase efficiency by not generating copies of variables
modifier function parameters. Make a member function of a Class A const member function, you cannot modify the value of a class's member variable in a function
const int & Print (const int a) const
The first const modifier returns a value that returns a constant reference and cannot modify the value of the return value
The second const modifier parameter, which means that the value of the parameter can no longer be changed in this function
The third const modifier, which indicates that the function is a constant function, cannot modify the value of a member variable in a class
At the same time, this function can only call the constant member variable
Reference type
Reference type, which is an alias for the variable, format: type identifier & function name (formal parameter list and description) {function Body}
1. You cannot return a reference to a local variable because the local variable is destroyed after the function returns, so the returned reference becomes a wild pointer and the program crashes
2. You cannot return a reference to the memory that is allocated by new, which may cause a leak to be stored
3, can return the reference of the class member, the single best is the const
This article is from the "Simon Eat Cattle" blog, please be sure to keep this source http://ximenchiniu.blog.51cto.com/9503623/1683404
The role of static, and const, and reference types in C + +