Pointer

Pointer

a pointer is a variable that points to memory location of another variable or references a memory location in which data is stored. In the computer, each memory cell has an address that can be used to access that location so a pointer variable points to a memory location we can access and change the contents of this memory location via the pointer.

Pointer declaration:

A pointer is a variable that contains the memory location of another variable in which data is stored. Using pointer, you start by specifying the type of data stored in the location.

The syntax is as shown below.

Data type * variable name

 

The following example illustrate the declaration of pointer variable :

int *ptr;
float *string;

 

Address operator:

Once we declare a pointer variable then we must point it to something we can do this by assigning to the pointer the address of the variable you want to point as in the following example:

ptr=#

The above code tells that the address where num is stores into the variable ptr. The variable ptr has the value 2220,if num is stored in memory 2220 address then

The following program illustrate the pointer declaration :

/* A program to illustrate pointer declaration*/

main()
{
int *ptr;
int sum;
sum=55;
ptr=&ptr;
printf (”\n Sum is %d\n”, sum);
printf (”\n The sum pointer is %d”, ptr);
}

error: Content is protected !!