Skip to content

Instantly share code, notes, and snippets.

@HarrisonJackson
Last active December 11, 2015 20:09
Show Gist options
  • Save HarrisonJackson/4653211 to your computer and use it in GitHub Desktop.
Save HarrisonJackson/4653211 to your computer and use it in GitHub Desktop.
Pass by reference vs value examples
void addTwo (int a){
a = a+2;
}
void duplicate (int a, int& b, int& c){
addTwo(a);
c = b;
cout << a;
}
int x = 5;
int y = 6;
int z = 7;
duplicate(x,y,z);
cout << x…y…z
int a = 2;
int b = 3;
int answer;
void passByReference(int a, int b, int& answer1){
answer = a+b;
}
passByReference(a,b,answer);
cout << answer;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment