Pointer Arithmetic
To understand pointer arithmetic, let us consider that ptr is an integer pointer that points to the address 1000. Assuming 16-bit integers, let us perform the following arithmetic operation on the pointer –
ptr++;
After the above operation, the ptr will point to location 1002 because whenever ptr is incremental, it will point to the following integer location which is 2 bytes beside the current location.This operation will move the pointer to the subsequent memory location without impacting the actual value at the memory location. If ptr points to a character whose address is 1000, then the above operation will point to the situation 1001 because the subsequent character will be available at 1001.
ptr++ is equivalent to ptr + (sizeof(pointer_data_type)).
- A pointer to an int accesses two successive bytes of memory.
- A pointer to a char accesses 1 consecutive byte of memory
- A pointer on a float takes up 4 consecutive bytes of memory.
- A double pointer takes up 8 consecutive bytes of memory.
The C language permits arithmetic operations on pointer variables. It is, however, the programmer’s responsibility to see that the outcome obtained by performing pointer arithmetic is the address of relevant and significant data.
Example program 1:
#include<stdio.h>
main()
{
int *a,*b,a1,b1;
a=&a1;
b=&b1;
printf("\nEnter values of a & b:");
scanf("%d%d",a,b);
printf("\nSum is %d",*a + *b);
printf("\nSub is %d",a1 - b1);
printf("\nMul is %d",*a * *b);
printf("\nDiv is %d",a1 / b1);
printf("\nRem is %d",*a % *b);
}
Output:

Example program 2:
#include<stdio.h>
main()
{
int i=3,*x;
float j=1.5,*y;
char k='c',*z;
printf("Value of i=%d\n",i);
printf("Value of j=%.2f\n",j);
printf("Value of k=%c\n",k);
x=&i;
y=&j;
z=&k;
printf("Original value in x=%u\n",x);
printf("Original value in y=%u\n",y);
printf("Original value in z=%u\n",z);
x++;
y++;
z++;
printf("New value in x=%u\n",x);
printf("New value in y=%u\n",y);
printf("New value in z=%u\n",z);
}
Output: