cpp学习笔记02
由于时效问题,该文某些代码、技术可能已经过期,请注意!!!本文最后更新于:3 年前
如题
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
| #include<iostream> #include<string> using namespace std;
void swap1(int a, int b) { int tmp = a; a = b; b = tmp;
}
void swap2(int *a, int *b) { int tmp = *a; *a = *b; *b = tmp; }
void showValue(const int &val) { cout << val << endl; }
void swap3(int &a, int &b) { int tmp = a; a = b; b = tmp; }
int& test2() { static int a = 10; return a; }
int main(int argc, char const *argv[]) { int a = 10; int &b = a;
int &aa = test2(); test2() = 100; cout << aa << endl;
return 0; }
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| #include<iostream> #include<string> using namespace std;
int func1(int a, int b=10);
int func1(int a, int b) { return a + b }
int func2(int a, int) { return a }
void func3(int &a) { cout << '' << endl; }
void func3(const int &a) { cout << 'const' << endl; }
int main(int argc, char const *argv[]) { func3(10);
return 0; }
|