Similar to other variables, pointer variables can also be used in expressions. For example, if p1 and p2 are two pointer variables then the following statements are valid

As a pointer holds the memory address of a variable, some arithmetic operations can be performed with pointers. Such as addition, subtraction, increment and decrement ext. However the following operations are not possible with pointers.

- Addition of two pointer address
- Multiplication of address
- Multiplication of address with a constant

Example: Write a C program to perform different arithmetic operations using pointers

#include<stdio.h> #include<conio.h.h> void main() { int a=10,b=20; int *p1,*p2; p1=&a; p2=&b; printf(" addition is %d",*p1+*p2); printf(" subtraction is %d",*p1-*p2); printf(" Multiplication is %d",*p1+*p2); printf(" division is %d",*p1+*p2); getch();

## 0 comments :

## Post a Comment

Note: only a member of this blog may post a comment.