And pointer references C ++ 2.3


pointer

And c language pointer, use no difference

int *p = 100;  //定义指针变量 p,指向的值为100
cout << *p << endl;  //以指针运算符 *,获取指针变量指向的值
cout << &p << endl; //以地址符 &,获取指针变量的 内存地址

Null pointer value

cpp11 adds a null pointer value nullptr. c98 use NULL.

int *p = nullptr;
int *q = NULL;

other

The function pointers; Pointer Pointer ...


Quote

Equivalent to a variable alias.

int n = 100;
int &p = n; //定义时必须初始化;必须是指向一个变量,而不能是字面值常量

More variable reference value, change the value of a variable point.


Reference pointer

Declare a pointer to a reference variable

int iv = 1024;
int &iva = iv;
int *q = &iva;
cout << iv << endl;
cout << iva << endl;
cout << *q << endl;

1024 will output


Pointer references

Alias ​​pointer variable. It is declared pointer references*&

int iv = 1024;
int &iva = iv;
int *q = &iva;

int *&p = q;
cout << *p << endl;

Continuous variables declared

Pointers and references, as when declaring a continuous variable, you need to specify each variable

int *a, *b, *c;
int *&aa=a, *&bb=b, *&cc=c;
Published 400 original articles · won praise 364 · Views 1.62 million +

Guess you like

Origin blog.csdn.net/jjwwmlp456/article/details/89605295