Demonstrate passing nonarrays by address. - C++ Function

C++ examples for Function:Function Parameter

Description

Demonstrate passing nonarrays by address.

Demo Code

#include <iostream>
using namespace std;
int do_fun(int &amt);  
int main()// www. j av a 2s .  com
{
   int amt;
   amt = 100;      
   cout << "In main(), amt is " << amt << "\n";
   do_fun(amt);    
   cout << "After return, amt is " << amt << " in main()\n";
   return 0;
}
int do_fun(int &amt)   
{
   amt = 85;       
   cout << "In do_fun(), amt is " << amt << "\n";
   return 0;
}

Result


Related Tutorials