C++之引用
来源:互联网 发布:去人声软件 编辑:程序博客网 时间:2024/06/05 07:38
引用
- 普通变量引用
- 结构体类型引用
- 指针类型引用
- 引用做函数参数
- 引用和指针的区别
变量类型引用
#include <iostream>using namespace std;int main(void){ int a = 5; int &b = a; //引用必须初始化 b = 10; cout << a << endl; //10 return 0;}
结构体类型引用
#include <iostream>using namespace std;typedef struct{ int x; int y;}Coor;int main(void){ Coor c1; Coor &c = c1; c.x = 5; c.y = 10; cout << c1.x << c1.y << endl;// 5 10 return 0;}
指针类型引用
using namespace std;int main(void){ int a = 5; int *p = &a; int *&q = p; //引用必须初始化 *q = 10; cout << a << endl; //10 system("pause"); return 0;}
引用做函数参数
#include <iostream>using namespace std;void fun(int &a,int &b){ int c = 0; c = a; a = b; b = c;}int main(void){ int x = 5, y = 21; cout << "x = " << x << endl; //5 cout << "y = " << y << endl; //10 fun(x, y); cout << "x = " << x << endl; //10 cout << "y = " << y << endl; //5 system("pause"); return 0;}
引用和指针的区别
待补充
0 0
- C++Primer读书笔记之引用
- c之引用作为参数
- C语言之指针,数组,引用
- C常见问题之头文件引用
- objective-c基础之引用计数
- 《唐老师C++》之const引用
- c,c++易错点之指针与引用
- 黑马程序员-Object C之循环引用
- C语言之指针,数组,引用
- Objective-C内存管理之引用计数
- 【C++】:C++之C++的引用
- C与C++之引用与指针
- 引用(c++)
- C++----引用
- c++-引用
- C ++ 引用
- 【c++】引用
- 【c++】引用
- 洛谷 P2530 [SHOI2001]化工厂装箱员
- leetcode #4: Median of Two Sorted Arrays
- Struts2学习之旅(2)
- Java容器五:Vector
- iOS简单使用description方法(参考大神博客+自己想法)
- C++之引用
- 淘宝API示例
- [基础算法]递归二分算法
- EditText焦点问题 Android开发之ListView+EditText-要命的焦点和软键盘问题解决办法
- 整数的各位数之和与指数的递归求法
- 51. magento 手动创建订单
- Unity Shaders and Effects Cookbook (D-1) 设置 ZTest 来实现遮挡半透效果
- LintCode:跳跃游戏
- 圣剑传说 玛娜传奇(Legend of Mana)(LOM) 怪物掉落道具