摘要: #includeusing namespace std;/* 二 引用 2.4 引用做函数返回值 注意:不要返回局部变量引用 用法:函数调用作为左值*/int & test_1(){ // 引用方式返回 int a... 阅读全文
posted @ 2021-03-12 15:56 yub4by 阅读(58) 评论(0) 推荐(0)
摘要: #includeusing namespace std;/* 二 引用 2.3 引用做函数参数 作用:函数传参时,可以利用引用让形参修饰实参 优点:可以简化指针修改实参(在此方面可以代替指针)*/void swap_1(... 阅读全文
posted @ 2021-03-12 15:55 yub4by 阅读(52) 评论(0) 推荐(0)
摘要: #includeusing namespace std;/* 二 引用 2.1&2.2 引用的语法和注意事项 作用:给变量取别名 语法:数据类型 &别名 = 原名 注意:引用必须初始化,且初始化后不可更改*... 阅读全文
posted @ 2021-03-12 15:54 yub4by 阅读(32) 评论(0) 推荐(0)
摘要: #includeusing namespace std;/* 1.3 new操作符 利用new在堆区创建数据时,会返回该数据对应的指针 new出来的堆区数据,手动释放用delete*/int * func(){ int * ... 阅读全文
posted @ 2021-03-12 13:09 yub4by 阅读(39) 评论(0) 推荐(0)
摘要: #includeusing namespace std;/* 1.2程序运行后 栈区 存放函数的参数、局部变量 注意:不要返回局部变量的地址,栈区开辟的数据由编译器自动释放 堆区 ... 阅读全文
posted @ 2021-03-12 13:08 yub4by 阅读(27) 评论(0) 推荐(0)
摘要: #includeusing namespace std;/* 一 内存分区模型 C++程序在执行时,将内存分为4个区域 1 代码区 存放函数体的二进制代码,由OS管理 2 全局区 ... 阅读全文
posted @ 2021-03-12 13:06 yub4by 阅读(59) 评论(0) 推荐(0)
摘要: #include#include#includeusing namespace std;#define MAX 1000struct Person{ string name; int sex; // 1男2女 int age; stri... 阅读全文
posted @ 2021-03-11 19:53 yub4by 阅读(39) 评论(0) 推荐(0)
摘要: #include#includeusing namespace std;/* 结构体-案例#2 三国英雄:5名英雄,通过冒泡排序按照年龄升序排列*/struct Hero{ string name; int age; string... 阅读全文
posted @ 2021-03-11 12:05 yub4by 阅读(45) 评论(0) 推荐(0)
摘要: #include#include#include //随机数用到#include //时间用到using namespace std;/* 结构体-案例#1 三个老师,每个老师带五个学生做毕设*/struct student{ strin... 阅读全文
posted @ 2021-03-11 12:05 yub4by 阅读(55) 评论(0) 推荐(0)
摘要: #include#includeusing namespace std;/* 结构体中const的使用场景 用const来防止误操作*/struct student{ string name; int age; int score... 阅读全文
posted @ 2021-03-11 12:05 yub4by 阅读(122) 评论(0) 推荐(0)