Things Not To Do with Pointers in C Programming
Dereferencing a null pointer leads to undefined behavior, typically resulting in a segmentation fault or crash.
A dangling pointer points to memory that has been deallocated or is no longer valid. Using such a pointer can corrupt data or crash the program.
Pointer arithmetic that exceeds the bounds of the array it points to can lead to undefined behavior.
Using pointers of one type to manipulate data intended for another type can lead to misinterpretation of the data layout, alignment issues, or crashes.
If malloc
fails, it returns NULL
. Using this pointer without checking can lead to crashes.
Writing outside the bounds of allocated memory can corrupt data, cause crashes, or lead to security vulnerabilities.
Using a combination of malloc/free
with array declarations or stack memory can confuse ownership and lifetime rules, leading to errors.
After free()
, a pointer becomes a dangling pointer. Reusing it without proper reinitialization can lead to undefined behavior.