005_linuxC++之_指针的引入
标签:space names amp ios inux 指针 return col linu
(一)直接看代码
1 #include 2 using namespace std;
3 int add(int a){
4 a = a + 1;
5 return a;
6 }
7 int add(int *a){
8 *a = *a + 1;
9 return *a;
10 }
11 int add_ref(int &b){
12 b = b + 1;
13 return b;
14 }
15 int main(int arg,char ** argv){
16 int a = 99;
17 int &c = a; /*使用符号&来进行引用,引用之后c++就相当于a地址中的数进行a++*/
18 cout/*传入的是参数*/ /*a = 99*/
19 cout"a = "/*a = 99*/
20
21 cout/*传入的地址*/ /*a = 100*/
22 cout"a = "/*a = 100*/
23
24 cout/*引用*/ /*a = 101*/
25 cout"a = "/*a = 101*/
26
27 c++; /*a = 102*/
28 cout"a = "/*a = 102*/
29 cout"c = "/*a = 102*/
30 return 0;
31 }
main.cpp
运行结果
005_linuxC++之_指针的引入
标签:space names amp ios inux 指针 return col linu
原文地址:https://www.cnblogs.com/luxiaoguogege/p/9690177.html
评论