use*_*650 1 c pointers constants
常量定义为程序无法更改的固定值.例如,直接值1, 2, 3, 'a'和类似的定义常量#define CONSTANT 100
所以我正在阅读Null Pointer,
NULL指针是在几个标准库中定义的值为零的常量.
但是可以改变指针变量,证明:
#include <stdio.h>
int main()
{
int *a = NULL; /* Declaration\Definition of pointer and initialization of NULL */
int b; /* Regular Declaration\Definition of variable */
a = &b; /* pointer now stores memory address of b variable */
return 0;
}
Run Code Online (Sandbox Code Playgroud)
因此,如果Null指针是常量,那么为什么我编译它没有错误.
在此之前我读过.
如果您没有要分配的确切地址,最好将NULL值分配给指针变量
因此,如果Null指针是常量,那么当案例出现时我们可以获取我们想要的地址,你怎么能分配它,常量不能被改变.
出于同样的原因,这有效:
int x = 1;
x = 2;
Run Code Online (Sandbox Code Playgroud)
您正在将常量复制到可变变量中,然后变换该变量.这不会以任何方式影响常量,因为它是副本.
如果您复印一本书然后在副本中记下一个注释,那么原始书籍是否具有相同的注释?