Skip to content

Instantly share code, notes, and snippets.

@asa55
Created April 3, 2020 20:53
Show Gist options
  • Save asa55/528ed04c2c8729af3e3937b252e4f0c5 to your computer and use it in GitHub Desktop.
Save asa55/528ed04c2c8729af3e3937b252e4f0c5 to your computer and use it in GitHub Desktop.
#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