Program to add two numbers using pointers

1 year ago Admin 0

Add two numbers using pointers

This article illustrates the concept of how to add two numbers using pointers in c/c++.

add two numbers using pointers

Here is the source code and output of both the programs.

C Programming language

Program


#include<stdio.h>
#include<conio.h>
void main()
{
 int num1,num2,*x,*y,result;
 clrscr();
 printf("Enter first number:- ");
 scanf("%d",&num1);
 printf("Enter second number:- ");
 scanf("%d",&num2);
 x = &num1;
 y = &num2;
 result = *x + *y;
 printf("Sum of two numbers is:- %d",result);
 getch();
}

After successfully compiling and executing the above C program,output is:-

add two numbers using pointers


C++ Programming language

Program


#include<iostream.h>
#include<conio.h>
void main()
{
 clrscr();
 int num1,num2,*x,*y,result;
 cout<<"Enter first number:- ";
 cin>>num1;
 cout<<"Enter second number:- ";
 cin>>num2;
 x = &num1;
 y = &num2;
 result = *x  +*y;
 cout<<"Sum of two numbers is:- "<<result;
 getch();
}

After successfully compiling and executing the above C++ program,output is:-

add two numbers using pointers


Comment below if you are facing any problem or you find any error in the above program and also subscribe to our newsletter for more updates.


Read more c/c++ Programs published by snapcout:-

Program to reverse an entered array
Program to check if a given matrix is an identity matrix
Program to convert centimeters into meter and kilometer
Program to sort an array using insertion sort
Program to find sum of individual digits of number using function


About article

Written By:- Admin

Published on:- 16/08/2018

Published By:- Snapcout


Don't forget to share the article if you like it:-