Returning a Value from a Function : Function Return « Function « C++






Returning a Value from a Function

Returning a Value from a Function

#include <iostream>

using namespace std;

int addNumbers(int, int);  

int main ()
{

   int firstNum, secondNum, sum = 0;

   cout << "Enter first number: ";

   cin >> firstNum;

   cout << "Enter second number: ";

   cin >> secondNum;

   sum = addNumbers (firstNum, secondNum);

   cout << firstNum << " + " << secondNum << " = " << sum;

   return 0;
}

int addNumbers (int x, int y)
{
   return x + y;
}

           
       








Related examples in the same category

1.Returning objects. Returning objects.
2.Return Value Of FunctionsReturn Value Of Functions