C Pointers

A pointer is a variable suitable for keeping memory addresses of other variables. The values you assign to a pointer are memory addresses of other variables or other pointers.

C pointers are characterized by their value and data-type. The value is the address of the memory location the pointer points to, the type determines how the pointer will be incremented/decremented in pointer or subscript arithmetic.

Pointers are used to manipulate arrays and they can be used to return more than one value from a function.

Pointers are declared by using the asterisk(*).
int *p;

Each variable has two attributes: address and value. The address is the location in memory. In that location, the value is stored. During the lifetime of the variable, the address is not changed but the value may change.

void main (void)

int i;
int * a;
i = 10;
a = &i;
printf (” The address of i is %8u \n”, a);
printf (” The value of i is %d\n”, i);
printf (” The value at that location is %d\n”, *a);



The address of i is 631672
The value of i is 10
The value at that location is 10

Arrays and Pointers

An array is actually a pointer to the 0th element of the array. Dereferencing the array name will give the 0th element. This gives us a range of equivalent notations for array access. In the following examples, arr is an array.

arr[0] *arr
arr[1] *(arr+1)
arr[n] *(arr+n)