Passed by value and passed by reference
#include <iostream>
using namespace std;
void addNumbers(int, int, int&);
int main ()
{
int firstNum, secondNum, sum = 0;
cout << "Enter first number: ";
cin >> firstNum;
cout << "Enter second number: ";
cin >> secondNum;
addNumbers (firstNum, secondNum, sum);
cout << firstNum << " + " << secondNum << " = " << sum;
return 0;
}
void addNumbers (int x, int y, int& z)
{
z = x + y;
}
Related examples in the same category