1.程序流程结构-结构体中const的使用struct student { string name; int age; int score; }; //将函数中的形参改为指针,可以减少内存空间,而且不会复制新的副本出来 void printStudent(const student *s){ // s-age150; //加入const后,一旦有修改的操作就会报错,可以防止我们误操作 cout姓名:s-name 年龄:s-age 得分:s-scoreendl; } int main(){ struct student s{张三,15,70}; //通过函数打印结构体变量信息 printStudent(s); return 0; }2.程序的内存模型-01内存四区-代码区//代码区//// 存放 CPU 执行的机器指令//// 代码区是共享的共享的目的是对于频繁被执行的程序只需要在内存中有一份代码即可//// 代码区是只读的使其只读的原因是防止程序意外地修改了它的指令3.程序的内存模型-02内存四区-全局区//全局区//// 全局变量和静态变量存放在此.//// 全局区还包含了常量区, 字符串常量和其他常量也存放在此.//// 该区域的数据在程序结束后由操作系统释放.//总结////- C中在程序运行前分为全局区和代码区//- 代码区特点是共享和只读//- 全局区中存放全局变量、静态变量、const修饰的全局变量 字符串常量//- 常量区中存放 const修饰的局部常量#includestdio.h #includeiostream using namespace std; //全局变量 int g_a10; int g_b10; //const修饰的全局变量 const int c_g_a10; const int c_g_b10; int main(){ //全局变量,静态变量,常量 //创建普通局部变量 int a10; int b10; cout局部变量a的地址:aendl; cout局部变量b的地址:bendl; cout全局变量g_a的地址:g_aendl; cout全局变量g_b的地址:g_bendl; //静态变量:在普通变量前面加static static int s_a10; static int s_b10; cout静态变量s_a的地址:s_aendl; cout静态变量s_b的地址:s_bendl; //常量 //字符串常量 cout字符串常量hello world地址:hello worldendl; //const修饰变量 //const修饰的全局变量 coutconst修饰的全局变量c_g_a地址:c_g_aendl; coutconst修饰的全局变量c_g_b地址:c_g_bendl; //const修饰的局部变量 int c_l_a10; int c_l_b10; coutconst修饰的局部变量c_l_a地址:c_l_aendl; coutconst修饰的局部变量c_l_b地址:c_l_bendl; return 0; }