Pointer
Definition
Declaration
Operators
Intialization
Definition
It is a special variable which holds address of
another variable of similar type.
Declaration
one can declare a pointer variable by using :
datatype * pointer-variable-name ;
datatype : It is basic datatype ( char , int , float , double )
* : It is an indirection operator (Asterisk) used to declare
pointer
pointer-variable-name : It is a valid name .
; It is delimiter which indicates end of declaration.
Example :
1) int * a;
a is pointer variable of type integer .
2) char * b;
b is pointer variable of type character.
3) double * c;
c is pointer variable of type double
iii) Operators in pointer
There are two operators used in pointers & they are :
i) * ( indirection operator )
It is used to declare pointer variable as well as it returns the
value of the refernced variable.
ii) & ( address of operator)
It is used to return address of a variable
Initialization of pointer
we can initialize a pointer variable as follows
int *a ; // pointer variable declaration
int b=5; // b is integer type variable with address 502
as per definition
a= &b ; // initialization of pointer
printf(“address of b = %p”,a); //502
if i have to access value of b through pointer then
*a= *(&b);
*a = value at (address of b)= 5
printf(“%d”,*a) ; // 5
WAP to show use of pointer
#include <stdio.h>
int main()
{
int *a; //ptr variable of type int
int b=456; // variable of type int
a=&b; // initialize pointer
printf("\n Address of b =%d",a);
printf("\n value of b=%d", *a);