Pointer type variable declaration:-
Pointer is defined as a variable used
to store memory address. It is similar to any other variable and must be
declared before it can be used. Just like an integer variable can hold any
integers each pointer to a specific data type, such as int, char, float,
double, etc.
Syntax:-
datatype *prtname;
Ex:- int
*a;
Note:- Asterisk is a unary operator i.e it operator
on one variable. Thus compiler can not confuse it with the same symbol used for
multiplication.
Ex:- int
a=20;
int b,x,y;
int *pa,*pb,*px;
pa=&a;
x=*pa;
b=x+a;
pb=&b;
px=&x;
y=*pa+*pb;
Result:-
pa will be 100
x will be 20
pb will be 40.
*pb will be 102.
*px+pb will have a value 60.
Pointer to a Pointer:-
a pointer to a pointer is a construct
used frequently in more complex programs. To declare a pointer to a pointer,
place the variable name after two successive asterisks(*).
Ex:- int
***z;
int r=5;
int *pr=&r;
int **p=&q;
No comments:
Post a Comment