Pointer
operators
There are two types of
pointer operators in 'C'. Those are
1. Address operator(&):
·
To store
the address of a variable into pointer variable
·
Control
string is used to display the address as output is eiether %u or %p
%u
--> Decimal format as output
%p
--> Hexadecimal format as output
2. value at(*):
·
It is a
special operator called indirect operator
·
It is
used to access the value of the variable by using pointer
Accessing
variable value through pointer:
The
value of a variable can be accessed through pointer variable using a unary
operator ‘*’, usually known as indirection
operator. The operator refers to “value at the address in”.
Example: *ptr refers to value at the address in ptr
/*
EXAMPLE PROGRAM TO DEMONSTRATE POINTERS CONCEPT */
main()
{
int x,*ptr;
clrscr();
printf("\nAddress of x
is:%u",&x);
printf("\nAddress of ptr
is:%u",&ptr);
x=10;
printf("\nx value using
x:%d",x);
ptr=&x;
printf("\nValue in
p:%u",ptr);
printf("\nx value using
ptr:%d",*ptr);
}
No comments:
Post a Comment