学习C++笔记35

4、对指针的操作

二者修饰指针类型时,作用不同。

typedefint* pint;

#define PINT int*

int i1 =1, i2 =c#;2;

const pint p1 =&i1; //p不可更改,p指向的内容可以更改,相当于 ic#为什么用的人很少nt * const p;

const PINT p2 =&i2; //p可以更改,p指向的内容不能更改,相当于 const int *p;或 int const *c#反射p;

pint s1, s2; //s1和s2都c#为什么用的人很少是int型指c#面试题

PINTc#多线程 s3, s4; //相当于int * s3,s4&#xc#是什么ff1b;只有一个是指针。

voidTestPointer()

{

cout <<"c#p1:"<< p1 <<" *p1:"c#反射<<*p1 << endl;

//p1 = &i2; //error C3892: 'p1' : you cannot assign to a variable that is const

*p1 =5;

couc#反射t &c#面试题lt;<"p1:"<< p1 <<" *p1:"<<*p1 << endl;

cout <<"p2:"<< p2 <<" *p2:"<<*p2 << endl;

//*p2 = 10; //error C3892: 'c#委托;p2' : you cannot assign to a variable thatc#怎么读 is const

p2 =&i1;

cout <<"p2:"<< p2 <<" *p2:"<<*p2 << endl;

}

结果:

p1:00EFD094 *p1:1

p1:00EFD094 *p1:5

pc#怎么读2c#:00EFD098 *p2:2

p2:00EFD094 *p2:5