C++ Program to add two numbers using call by Reference


In this program, You will learn how to add two numbers using call by Reference in C++.


Call by Reference

void sum(int a,int b,int *s){}


Example: How to add two numbers using call by Reference in C++

Run it Now
#include<iostream>
using namespace std;

void sum(int a, int b, int *s) {
    *s = a + b;
}

int main() {

    int a, b, s;

    cout << "Enter Two Numbers :";
    cin >> a>>b;

    sum(a, b, &s);
    cout << "\nThe Sum is:" << s;

    return 0;
}

Output:

Enter Two Numbers :12 13
The Sum is:25