2019/9/3 null pointer and the pointer field

void * pointer, the type of null pointer, the pointer can point to any type of
int a =10;
void *pa = &a;
int b = (* (int *) pa); // correct int b = (int *) (* pa) is wrong
 
Field guide: pointing to illegal memory pointer or have been destroyed
Hazard: The cause unpredictable damage to the operating system
The reason:
1, the pointer does not point definition, i.e., not initialized
Solution: Either point to legitimate space, either point to NULL (#define NULL ((void *) 0))
char *p = NULL;
char *p = (char *)malloc(100);
 
2, then the pointer is free or delete, the pointer is just freed memory, the pointer value is not changed. At this point p reduced to a "field guide", p point does not make sense
Solve: free (p);
p = NULL; (blank)

Guess you like

Origin www.cnblogs.com/epll/p/11450652.html