我们在编写程序时使用指针时我们需要对指针进行检验,即是我们对其进行断言判断处理,现在我们举例说明:
1,新建exception.c
#include<stdio.h>
#include<assert.h>
#include<stdlib.h>
#include<string.h>
void memory_app(int** p)
{
assert(*p != NULL);
*p = NULL;
*p = (int*)malloc(100);
}
void memory_cpy(char** p)
{
*p = (char*)malloc(1024);
assert(p != NULL);
}
void memory_exception(char* e_pointer)
{
assert(e_pointer != NULL);
}
int main()
{
int a = 10;
int* p_pointer = &a;
memory_app(&p_pointer);
assert(p_pointer != NULL);
char* s = "tangtang";
char * s_pointer = NULL;
memory_cpy(&s_pointer);
assert(s_pointer !=NULL);
strncpy(s_pointer,s,size