C语言指针、表达式与运算符详解
1. 指针相关知识
1.1 指向常量类型的指针
指向常量限定类型的指针有时被称为只读指针。虽然可以修改指针的值,但不能使用它们来修改所指向的对象。例如:
+ 3;
*ciPtr *= 2; // Error: you can't change an object referenced by
// a pointer to const int.
*(int *)ciPtr *= 2; // OK: Explicitly converts the pointer into a
// pointer to a nonconstant int.
1.2 空指针常量
空指针常量是值为 0 的整数常量,或者是值为 0 的常量整数转换为 void
指针。宏 NULL
在头文件 stdlib.h
、 stdio.h
等中被定义为空指针常量。示例如下:
#include <stdlib.h>
long *lPtr = NULL; // Initialize to NULL: pointer is not ready for use.
/* ... operations here may assign lPtr an object addre