Created
April 3, 2020 20:53
-
-
Save asa55/528ed04c2c8729af3e3937b252e4f0c5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#define print(s) std::cout << s << std::endl; | |
int increment0(int value) { | |
value++; | |
return value; | |
} | |
void increment1(int& value) { | |
value++; | |
} | |
void increment2(int* value) { | |
(*value)++; | |
} | |
int main() { | |
int a = 5; | |
print(a); | |
a = increment0(a); // pass by value | |
print(a); | |
increment1(a); // pass by reference | |
print(a); | |
int* b = &a; | |
increment2(b); // pass by reference using pointers | |
print(a); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment