#include<stdio.h>
#include<stdlib.h>
#include<string.h>
static int*p;
int main()
{
printf("static no initial:\n");
if(p==0)printf("p==0\n");
if(p>0)printf("%s","p>0\n");
if(p==NULL)printf("%s","p==NULL\n");
printf("set p=0x0:\n");
p=0x0;
if(p==0)printf("%s","0x0==0\n");
if(p>0)printf("%s","0x0>0\n");
if(p==NULL)printf("%s","0x0==NULL\n");
// 指针无指向,段错误
// printf("memset:\n");
// memset(p,0,sizeof(int*));
// if(p==0)printf("%s","memset==0\n");
// if(p>0)printf("%s","memset>0\n");
// if(p==NULL)printf("%s","memset==NULL\n");
// 指针无指向,段错误
// printf("bzero:\n");
// bzero(p,sizeof(p));
// if(p==0)printf("%s","bzero==0\n");
// if(p>0)printf("%s","bzero>0\n");
// if(p==NULL)printf("%s","bzero==NULL\n");
p=(int*)malloc(sizeof(int));
printf("\nmemset:\n");
memset(p,0,sizeof(int*));
if(p==0)printf("%s","memset==0\n");
if(p>0)printf("%s","memset>0\n");
if(p==NULL)printf("%s","memset==NULL\n");
if(0==*p)printf("*p==0\n");
else if(*p>0)printf("*p>0\n");
printf("\nbzero:\n");
bzero(p,sizeof(p));
if(p==0)printf("%s","bzero==0\n");
if(p>0)printf("%s","bzero>0\n");
if(p==NULL)printf("%s","bzero==NULL\n");
if(0==*p)printf("*p==0\n");
else if(*p>0)printf("*p>0\n");
free(p);//与malloc成对使用
p=NULL;
return 0;
}
//结果
static no initial:
p==0
p==NULL
set p=0x0:
0x0==0
0x0==NULL
memset:
memset>0
*p==0
bzero:
bzero>0
*p==0