20. write a C program to perform arithmetic operations using pointers


Program to perform arithmetic operations using pointers

Source Code:

 #include<stdio.h>
int main()
{
int a=1,b=2,c;
int *d1,*d2;
d1=&a;
d2=&b;
c=*d1+*d2;
printf("%d\n",c);
c=*d1-*d2;
printf("%d\n",c);
c=*d1 * *d2;
printf("%d\n",c);
c=*d1 / *d2;
printf("%d\n",c);
c=*d1 % *d2;
printf("%d\n",c);
return 0;
}

Output:

3
-1
2
0
1

No comments:

Post a Comment