- Fundamentally, a pointer is a number. Very often, it is represented as a hexadecimal number.
- If the hexadecimal number is a valid memory location, then it is deemed to be a valid pointer. If not, it is a illegal pointer. Consider that a_var is a integer variable. The unary operator & gets the memory address of any variable that has been defined. Therefore, the expression &a_var will evaluate to a valid pointer.
- A pointer variable is used to store a pointer value.
int *pointer_a = &var_a;
In the above code, pointer_a is initialised with the memory address of var_a variable. Proper attention must be taken to assign a valid pointer value to pointer variable. Otherwise, when the unary operator * is used to de-reference a pointer variable, it may result in a program crash or illegal memory access.
int *pointer = 0; // not a valid memory location
printf ("%d", *pointer); // de-referencing an illegal pointer value may likely cause program crash