Pointer :-
·
It is
avariable that represents the location of a data item.
·
It can be
declared as a variable or an array.
· They can
be used to pass information back and forth between the calling
and its reference point.
and its reference point.
· They
are closely associated with arrays and provide an alternate way to
Access Individual array elements.
· They
provide a convenient way to represent multi dimensional arrays.
· They
allow a single multidimensional array to be replaced by a lower - dimensional
array of pointers, which permits a group of strings
to be represented within a single array, where the individual strings
may differ in length.
Declaration of a pointer :-
datatype variablename pointer ;
example :-
int a=10,*p;
p = address of a;
*p = value of a;
to be represented within a single array, where the individual strings
may differ in length.
Declaration of a pointer :-
datatype variablename pointer ;
example :-
int a=10,*p;
p = address of a;
*p = value of a;
FUNDAMENTAL CONCEPTS :-
· Every
data item declared occupies one or more continuous memory cells
in computer memory.
in computer memory.
· The
number of memory cells required to store data item depends on the
type of the data item.
type of the data item.
· For
every identifier that is declared the compiler automatically assigns
memory cells.
memory cells.
· The
data item can be accessed if we know the location of the first memory
cell as within a computer the memory cells are numbered consequently.
cell as within a computer the memory cells are numbered consequently.
· The
number associated with each memory cell in Known as
as memory cells address.
as memory cells address.
· The
address of memory location is determined by the unary or address
operator “&”, which evaluates the address of the operand.
operator “&”, which evaluates the address of the operand.
· If
the address of a memory location is assigned to another variable,
then that variable is termed as “Pointer”.
then that variable is termed as “Pointer”.
· A
Pointer always holds the address of the memory location but not the value.
· Therefore
the memory location which is holding the address of another
memory location is called as pointer variable.
memory location is called as pointer variable.
·
The data represented by the variable ‘x’ can be accessed by the expression
*y where “*” is a ‘unary operator’ which is called as ‘Indirection operator’,
which is used to operate only on a pointer variable.
· The Indirection Operator "*" can act only upon the OPERANDS that
are POINTERS(pointer variable).
· Therefore an indirect reference can appear in place of any ordinary variable.
Value of ‘x’ ------------------------> Value of ‘y’ |
Y is a pointer variable to x’s location
|
The data represented by the variable ‘x’ can be accessed by the expression
*y where “*” is a ‘unary operator’ which is called as ‘Indirection operator’,
which is used to operate only on a pointer variable.
The
‘Address Operator’ “&” can act upon
the addresses are associated
with UNIQUE ADDRESSES therefore it cannot operate upon
ARITHMETIC EXPRESSIONS.
with UNIQUE ADDRESSES therefore it cannot operate upon
ARITHMETIC EXPRESSIONS.
0 comments:
Post a Comment