Mega Code Archive

 
Categories / C++ Tutorial / Function
 

Change a call-by-value parameter does not affect the argument

#include <iostream>  using namespace std;    double f(double x);    int main()  {    double t = 10.0;      cout << "1/10.0 is " << f(t) << "\n";      cout << "Value of t is still: " << t << "\n";      return 0;  }    double f(double x)  {    x = 1 / x;   cout << "inside f " << x << "\n";    return x;  } inside f 0.1 1/10.0 is 0.1 Value of t is still: 10