Introduction to pointer
It is the way to refer a memory location. A pointer variable can contain the address of another variable.
Suppose we declare integer variable a as :
Variable a has following properties :
1. Name of variable:
A variable must have a name. In above example, a is a variable of int consuming 2 bytes of memory because int has memory of 2 bytes.
2. Value of variable:
It is the value assigned to the variable.
3. Memory location of variable:
Variable is stored at some memory location. Memory location is represented as a number be in decimal or hexadecimal form.
Operators associated with a pointer variable
There are two operators associated with pointers. They are as follows:
i. * (Indirection)
This operator is used to specify that variable being declared is a pointer variable. It is also used to used to refer to the value of variable whose address is stored in pointer variable.
ii. &(Address )
It is used to refer to the memory location of a variable.
NULL specifies “points to nothing”. It represents that a pointer variable does not have any address stored into it.
We can determine the address of a variable with the help of address operator (&).
We can access value of a pointer variable using indirection operator.
y=&x; /* y contains the address of variable x*/
z=*y; /* *y contains the value of variable x whose address is contained in pointer variable y*/
|Program to demonstrate pointers|
Best Books of C