++ Operator: - It is referred as increment operator that increments the value of variable. If ++ operator is used with pointer variable, then pointer variable points to next memory address that means pointer increment with respect to size of the data type used to declare pointer variable.
Example:-
int a[5]={10,20,30,40,50},*ptr;
ptr=a[0];
for(i=0;i<5;i++)
{
cout<<*ptr;
ptr++;
}
In the above example, ptr points to memory location of a[0].
Increment statement ptr++ increments ptr by memory size of int i.e 2 bytes and ptr points to a[1].
- - Operator: - It is referred as decrement operator that decrements the value of variable. If - - operator is used with pointer variable, then pointer variable points to previous memory address that means pointer decrement with respect to size of the data type used to declare pointer variable.
Example:-
int a[5]={10,20,30,40,50},*ptr;
ptr=a[4];
for(i=0;i<5;i++)
{
cout<<*ptr;
ptr- -;
}
In the above example, ptr points to memory location of a[4].
Decrement statement ptr- - decrements ptr by memory size of int i.e 2 bytes and ptr points to a[3].