Skip to content

Commit 4b4881d

Browse files
committed
Pass by value/reference exercise
1 parent 39646bc commit 4b4881d

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
hello :)
44

5+
https://bcs.wiley.com/he-bcs/Books?action=index&itemId=0470383275&bcsId=6384
6+
57
https://code.visualstudio.com/docs/cpp/config-linux#_debug-helloworldcpp
68

79
https://clang.llvm.org/docs/ClangFormatStyleOptions.html
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include <iostream>
2+
3+
// Pass by value
4+
void print_a(int x) {
5+
std::cout << "print(int x): " << ++x << std::endl;
6+
}
7+
8+
// Pass by reference
9+
void print_b(int& x) {
10+
std::cout << "print(int& x): " << ++x << std::endl;
11+
}
12+
13+
int main(int argc, char const* argv[]) {
14+
int num = 5;
15+
std::cout << "num = " << num << std::endl << std::endl;
16+
17+
print_a(num);
18+
std::cout << "num = " << num << std::endl << std::endl;
19+
20+
print_b(num);
21+
std::cout << "num = " << num << std::endl << std::endl;
22+
23+
return 0;
24+
}

0 commit comments

Comments
 (0)