Introduction
Pointers
are one of the most powerful features available in C. The use of pointers
offers a great degree of flexibility for manipulating data in programs and
making programs quicker and memory efficient. Most of the learners feel that
understanding pointer is very daunting task, but it is not so. Although
programming can be done without the use of pointers but in some situations,
pointers show its real power such as:
a) Creation of linked data
structures such as Linked Lists, Trees, Graphs.
b) Management of objects which
are allocated memory dynamically.
c) Passing arrays, strings to
functions more efficiently.
d) To pass function arguments
that will be changed by the function.
e) To return more than one
value from the function.
f) To pass address of structures
or objects instead of entire object to functions.
g) Optimize the program to
execute faster or use less memory.
When you define a variable in C, the compiler reserve a
memory location to store that variable
For example: Consider a statement,
int i=10;
On
execution of the above statement, the compiler reserves the memory location
(say 3302), associate the variable name i with the memory location and then stores the value 10 in it
as shown in above figure. The programmer can access or store the value using
the name of the variable without any care of the memory location in which the
value is stored.
However, sometimes you may want to
access this value using its memory address instead of variable name due to
performance reasons. It is only possible by placing the address in some other
variable known as pointer.
Post a Comment