void 与 null

void 指针称为通用指针,可以指向任意类型,

#include<stdio.h>
int main(){
	char a[]="dajiahao";
	char *p="Helo,world";
	printf("%s\n",p);
	printf("%s",a);
}
#include<stdio.h>
int main(){
	int num=1024;
	int *pi=#
	char *ps="Helloworld!";
	void *pt=pi;
//	printf("pi:%p  pt:%p\n",pi,pt);
	printf("%d\n",*(int*)pt);//注意强转
	pt=ps;
//	printf("pt:%p  ps:%p",pt,ps);
	printf("%s",(char*)pt);
	return 0;
}

NULL空指针

当不知道将指针初始为什么地址时,请将它初始化为NULL,在对指针进行解引用时,先检查该指针是否为NULL

#include <stdio.h>

int main()
{
	int *p1;
	int *p2 = NULL;

	printf("%d\n", *p1);
	printf("%d\n", *p2);

	return 0;
}

NUL 不是 NULL

 NULL用于指针和对象,表示控制,指向一个不被使用的地址,而'\0' 表示字符串的结尾

猜你喜欢

转载自www.cnblogs.com/helloworld2019/p/11105015.html