Home » C Programming » Arithmetic Operation With Pointer

Arithmetic Operation With Pointer

In a C programming, we can also perform arithmetic operations with pointer.

There are four arithmetic operators that can be performed with pointers:

  • Increment (++)
  • Decrement ( — )
  • Addition ( + )
  • Subtraction ( – )

 For a simple variable
int a=3;
a++; //print 4
Increment integer value by one.

Pointer is a variable which can hold the address of another variable in above code

For pointer
int a=3;
int *ptr;
ptr=a;
ptr++; //increment by one integer address space

pointer variable address value are incremented based on type of values it holds

Increment a Pointer

Example: Write a program in c language, to increments the variable pointer to access each succeeding element of the array.

OUTPUT

In above program we can also decrements the pointer.

In above program you have to loop in decrement way as below

Please follow and like us:
error