我一直在写类似的东西
char *x=NULL;
Run Code Online (Sandbox Code Playgroud)
假设是
char *x=2;
Run Code Online (Sandbox Code Playgroud)
会创建一个char指向地址2 的指针.
但是,在GNU C编程教程中,它表示int *my_int_ptr = 2;将整数值存储2到my_int_ptr分配时的任何随机地址.
这似乎意味着我自己char *x=NULL正在将NULL一个cast 的值分配给char内存中的某个随机地址.
而
#include <stdlib.h>
#include <stdio.h>
int main()
{
char *x=NULL;
if (x==NULL)
printf("is NULL\n");
return EXIT_SUCCESS;
}
Run Code Online (Sandbox Code Playgroud)
事实上,印刷品
一片空白
当我编译并运行它时,我担心我依赖于未定义的行为,或者至少是指定不足的行为,我应该写
char *x;
x=NULL;
Run Code Online (Sandbox Code Playgroud)
代替.