本文共 1448 字,大约阅读时间需要 4 分钟。
C++程序在执行时,将内存划分为4个区域:代码区、全局区、栈区和堆区。每个区域的内存管理方式和生命周期不同,理解这些区别对后续编程有重要意义。
new
和delete
操作符进行内存管理。数据类型 &别名 = 原名
。int &b
。void mySwap(int &a, int &b) { int temp; temp = a; a = b; b = temp;}
int &test01() { static int a = 10; return a;}
int *const ref = &a
。void showValue(const int &val) { cout << "val = " << val << endl;}
返回值类型 函数名 (参数=默认值) {}
void func(int a, int) {}
void func(int &a) {}void func(const int &a) {}
类名() {}
~类名() {}
class Person { public: Person(int age) { this->age = age; } int age;}
const
。const
。转载地址:http://xuhwz.baihongyu.com/