Scope {} const qualifier reference code block

Simply divided into: global scope, local scope, the scope statement
If you want the scope of local variables using the same name as a global variable, the variable can be added before the "::"
:: I = 20
#include<iostream>
using namespace std;
was int = 20;
int main(int argc, char *argv[])
{
    was int = 10;
    cout<<var<<endl;   //10
    cout<<::var<<endl;  //20
    return 0;
}
 
In C ++, the name of the structure, the joint names (common name body), names are enumerated type name.
Structures, unions, and enumerations name can be used directly as the type name
#include<iostream>
using namespace std;
struct Student {
    string name;
    int age;
};
int main(int argc, char *argv[])
{
    Student stu;
    return 0;
}
 
{} Block
If the variable is defined in the block "{}", the lifetime and the scope of this variable will be limited in the code block.
#include<iostream>
using namespace std;
int main(int argc, char *argv[])
{
    was int = 20;
    {
        was int = 30;
        cout<<var<<endl;  //30
    }
    cout<<var<<endl;  //20
    return 0;
}
 
const qualifier
const int LIMIT = 100;
LIMIT = 100;  //error
int* p = &LIMT; //error
const qualifier
Modifiers Modifiers constants defined by const const. General grammatical case
const type name name = constant value constant (expression);
For the above example, with the const is defined as:
   fun(&LIMIT); //error void fun(int
*a);
Pointing constant pointer variable:
Such as: const char * p_name = name1;
Chang (amount) pointer:
Such as: char * const p_name = name1;
Constant constant point (amount) pointer:
如: const char * const name = "chen";
 
Quote:
A reference to the variable is an alias to make pointer arithmetic easier
Referenced definitions
Type name = & alias variable name or alias; 
如:int a=5;int &b=a;
 
Reference must be initialized when defined, then can not re-assign a new value
Examples of errors: 
int a;
int & b; // error 
b = a;
Initialization can refer to another name, as follows:
int a;
int &b = a;
int &c = b;
The effect produced by the same reference parameter is transmitted by the same address
Reference syntax clearer when passing simple function call arguments do not add "&" symbol 
Do not add "*" symbol in front of the called function in the parameter 

Guess you like

Origin www.cnblogs.com/gschain/p/11244479.html