- 2.21
int i = 0;
double dp = &i; //int类型的值不能初始化double*类型的实体。
int ip = i; //int类型的值不能初始化int类型的实体。
int *p = &i; //正确。
- 2.22
if(p) //如果p不为空则为真
if(*p) //如果 *p的值非0则为真
- 2.23
首先要确定指针是否合法,才能判断它指的对象是不是合法的。
- 2.24
int i = 42;
void *p = &i; //void指针可以指向任何类型的对象。
long lp = &i; //int类型的值不能初始化long*类型的实体。
- 2.25
int * ip, i, &r = i; //ip为int*类型, i为int型, r是i的引用。
int i, *ip = 0; //i为int型, ip为空指针。
int * ip, ip2; //ip为int*类型, ip2为int型。
- 2.26
const int buf; //不合法,buf必须初始化。
int cnt = 0; //合法。
const int sz = cnt;