Pointers, the concept which a c beginner find difficult to understand. Even if you once read it carefully, you cannot be hell sure that you will be able to work with pointers conveniently. Here is a quick technical article which may help you understand pointers deeply.
Misconception: Pointer is an address to a VARIABLE.
A pointer points to an address, but the address need not be the address of a variable. It may be address of any location in the computer memory. For example,
int i=10, *pi;
pi=&i;
Here ‘pi’ is a pointer variable pointing to the location of ‘i’. Be careful, it does not point to ‘i’, it points to its location only. Now if we change either ‘i’ or ‘*pi’, the corresponding value at the location will change. Here
arises the misconception that ‘pi’ is associated with ‘i’, which is not. Consider the following example:
int *pi;
pi=(int *)malloc(sizeof((int));
/* malloc is a function to dynamically allocate memory to a pointer. It returns ‘void *’, which is typecasted as ‘int *’ */
*pi=1024;
printf(“The value at pi is”,*pi);
free(pi);
Here ‘pi’ is a pointer which points to an integer value. But it does not points to some variable, but a memory location is allocated to it using ‘malloc’.
Hence we conclude that a pointer is a variable which points to a memory location and not particularly the location of a variable.