Answers for "pass by value and pass by reference c++"

C++
0

pass by value and pass by reference c++

#include <iostream>
using namespace std;

void by_value(int x) {
  x *= 2;
}

void by_reference(int &x) {
  x *= 2;
}

int main() {
  int a1 = 5, a2 = 5;

  cout << "Before: a1 = " << a1 << ", a2 = " << a2 << "\n";
  
  by_value(a1);
  by_reference(a2);

  cout << "After: a1 = " << a1 << ", a2 = " << a2 << "\n";

  return 0;
}
Posted by: Guest on May-24-2021

Code answers related to "pass by value and pass by reference c++"

Browse Popular Code Answers by Language