Home : C Language : Variables : Pointers
Are declared thus:
name refers to the value of the pointer variable, which should be the address of a variable of type type.
*name refers to the value of the variable of type type,
pointed to by the address in the pointer variable.
Pointers may only have addition and subtraction operations performed on them, which are always calculated in the units of the size of their type.
Pointers to functions are declared thus:
And the pointed to function can be called thus:
short int IntegerArray ;
short int* IntegerPtr;
might result in the following addresses being assigned:
The following code could then be written:
IntegerPtr = &IntegerArray ;
The base address of IntegerArray (0x1000) is stored in IntegerPtr (at addresses 0x1006 and 0x1007).
*(IntegerPtr + 3) = 12;
Each short int takes 2 bytes, so 2 * 3 = 6 is added to the address stored in IntegerPtr (0x1000) to give an address of 0x1006. The value 12 (0x000C) is then stored at addresses 0x1006 and 0x1007 (IntegerArray ).