Â
In this, we are going to see how to perform Arithmetic Operations using Pointers in C++ Programming Language.
The Code given below can be used for TURBO C++ Compilers: -
//C++ program for performing arithmetic operation using pointers.
#include <iostream.h>
#include <conio.h>
void main()
{
clrscr();
float x, y, add, sub, mul, div;
cout << "Enter 2 numbers:-\n";
cin >> x >> y;
float *p = &x;
float *q = &y;
add = (*p) + (*q);
sub = (*p) - (*q);
mul = (*p) * (*q);
div = (*p) / (*q);
cout << "Addition:- " << add << endl;
cout << "Subtraction:- " << sub << endl;
cout << "Multiplication:- " << mul << endl;
cout << "Division:- " << div;
getch();
}
//...........Coded by YASH ALAPURIA
The Code given below can be used for gcc/g++ Compilers: -
//C++ program for performing arithmetic operation using pointers.
#include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{
system("cls");
float x, y, add, sub, mul, div;
cout << "Enter 2 numbers:-\n";
cin >> x >> y;
float *p = &x;
float *q = &y;
add = (*p) + (*q);
sub = (*p) - (*q);
mul = (*p) * (*q);
div = (*p) / (*q);
cout << "Addition:- " << add << endl;
cout << "Subtraction:- " << sub << endl;
cout << "Multiplication:- " << mul << endl;
cout << "Division:- " << div;
return 0;
}
//...........Coded by YASH ALAPURIA
#ENJOY CODING
Post a Comment
FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP