Pointers:-
A Pointer is a variable that holds the
memory address of another variable. The storage and retrieval of data using the
memory address of a variable (i.e. a pointer) is faster than that of using
variable. To declare and refer to a pointer type variable, C provided two special
unary operator namely * and &.
Benefits of Pointers:-
Passing
arguments to functions by address when modifications of formal arguments are to
be reflected on actual arguments.
Passing arrays
and strings more conveniently form one function to another.
Manipulating
arrays more easily by moving pointers to them instead of moving the arrays
themselves.
Creating
complex data structure, such as linked lists are binary tree, where one data
structure must contain references to other data structures.
The &(Address of) and *(dereferencing) operator:-
All the variables defined in a program
reside at specific addresses in the memory of computer. it is possible to
obtain the address of a variable by using the &(ampersand) operator.
The other pointer operator available
in C is the character ‘*’ and this is called value at address operator. It
returns the value stored at a particular address. (indirection operator)
Ex:-
main()
{
int a=2;
printf(“\n Address of a=%d”,&a);
printf(“\n value at
address a=%d”,a);
printf(“\n value of
a=%d”,*(&a));
}
No comments:
Post a Comment