diff --git a/guide/english/c/pointers/index.md b/guide/english/c/pointers/index.md index bf9c7db151..2d21483d4c 100644 --- a/guide/english/c/pointers/index.md +++ b/guide/english/c/pointers/index.md @@ -249,6 +249,19 @@ int main(void) } ``` + +## Null Pointer +Consider following line +```c +int *p; +``` +We have created a pointer which contain garbage value. If we try to dereference it, we will read the value stored at the garbage address and this can lead to unexpected results, such as segmentation fault. Hence we should never leave a pointer uninitialized and instead initialize it to NULL, to avoid unexpected results. +```c +int *p = NULL; // NULL is a constant with value 0 +int *q = 0; // same as above +``` + + ### Void Pointer A void pointer is a pointer variable declared using the reserved word in C ‘void’. Lets illustrate this with a void pointer declaration below: @@ -296,7 +309,6 @@ Example: ``` Credits: - # Before you go on... ## A review * Pointers are variables, but instead of storing a value, they store a memory location.