Pointers

Sunday, 14 August 2016

Pointers:

  • A variable which holds the address of the another variable is known as pointer.
  • pointer points to existing variable.

Pointer Declaration:

  •  Now  we store address of the variable into another variable so that another variable should be a special variable that special variable name is pointer variable.
  •  To declare a pointer we use * (indirection operator)
Syntax: Datatype  *pointer-name;
Example:           int  *P;
from the example we noticed that p is pointer to integer datatype and p contains the address of variable which is integer variable.

Initialization: 

  • Here we assign the address of a variable to a pointer variable and this can be done by using &sign.
  • Here  (&) is an address operator used to access the address of a variable and assign it to a pointer to initialize it. 
Consider  an example of pointer initialization:
                            int  i=10;
                            int  *P;
                            P=&i;
This can be shown as :
here  p is 2000
  *p is 10
&p  is 1998 

  •  we  have to observe that we cannot assign the address of a float variable into integer pointer.
                          float x;
                          int *P;
                          p=&x;  /*error*/

          /*sample program on pointer concept*/           






























    Uses of pointers:

  • Pointers are used to save memory space.
  • pointers allows  'c'  to support dynamic memory management.
  • pointers reduce complexity and length of a program. 
You can also refer
----------------------------------------------------------------------------------------------------------


3 comments: