Calling a function by value copies the argument and stores it in a local variable for use by the function, so the argument is unaffected if the value of the local variable changes.
The argument is passed to the function as a reference rather than a copy, so if the function changes the value of the argument, the argument is also changed.
The void change(int); function prototype informs the compiler that there is a function named change that takes a single int argument and returns void (i.e. nothing).
Because there is no & with the argument, it is called by value.
You have the line change(orig); later in your code, which actually calls the function with.
Take a look at the output of this program:
#include<iostream>
using namespace std;
int main(){
void change(int);
void change2(int&);
int x = 10;
cout<<"The original value of x is: "<< x <<"\n";
change(x); // call change(), which uses call by value
cout<<"Value of x after change() is over: "<< x <<"\n";
change2(x); // call change2(), which uses call by reference
cout<<"Value of x after change2() is over: "<< x <<"\n";
return 0;
};
void change(int orig){
cout<<"Value of orig in function change() at beginning is: "<<orig<<"\n";
orig=20;
cout<<"Value of orig in function change() at end is: "<<orig<<"\n";
return;
}
void change2(int &orig){
cout<<"Value of orig in function change2() at beginning is: "<<orig<<"\n";
orig=20;
cout<<"Value of orig in function change2() at end is: "<<orig<<"\n";
return;
}
I've changed int orig in main() to int x to hopefully avoid name confusion, and I've added change2() which uses call by reference.