摘要:
构造函数和析构函数 #include<iostream> using namespace std; class example{ public: example(){ cout << "调用构造函数" << endl; } ~example(){ cout << "调用析构函数" << endl; 阅读全文
posted @ 2026-05-19 19:23
www6526
阅读(5)
评论(0)
推荐(0)
摘要:
访问权限: 公共权限 public 类内可以访问 类外可以访问 保护权限 protected 类内可以访问 类外不可以访问 class Person{ public: string name; protected: string car; private: string password; publ 阅读全文
posted @ 2026-05-18 16:29
www6526
阅读(5)
评论(0)
推荐(0)
摘要:
引用 本质上引用是一种C++内部实现的简化版指针操作,同样是透过变量名到地址操作内存。 int& ref = a; // <==> int* const ref = &a; 因此,引用一旦初始化以后就不能改变 关于引用做函数返回值 #include <iostream> #include <stri 阅读全文
posted @ 2026-05-17 16:49
www6526
阅读(6)
评论(0)
推荐(0)
摘要:
C++程序将代码分成四个区:代码区,全局区,栈区,堆区。 代码区 存放编译后的二进制代码,由操作系统管理。 生命周期:从程序被加载到内存开始,到程序结束退出为止 代码区是共享的:对于需要频繁执行的程序和代码,只需要存放一次代码即可 代码区是只读的:代码编译成功即固定,防止程序意外修改指令 全局区 存 阅读全文
posted @ 2026-05-16 19:38
www6526
阅读(8)
评论(0)
推荐(0)
摘要:
结构体 用户自定义的数据类型 声明示例: struct student{ string name; int age; int score; }s; 创建结构体变量 (struct) student s1; s1.name = "..."; s1.age = ; s1.score = ; (struc 阅读全文
posted @ 2026-05-12 16:25
www6526
阅读(3)
评论(0)
推荐(0)
摘要:
定义指针 定义示例: int a = 10; int *p; p = &a; ##指针只记录变量的内存地址 使用指针 解引用:* p; ##通过解引用*p指向a的地址,取出数据 空指针和野指针 空指针:主要用于初始化变量。int *p = nullptr; 空指针p会指向地址为0的内存。0-255内 阅读全文
posted @ 2026-05-11 22:11
www6526
阅读(6)
评论(0)
推荐(0)
摘要:
函数定义 示例: int name(int a){ a += a; return a; } 调用函数 示例: int main(){ int x = 10; x = name(a); return x; } 其他 正常情况下函数内部的操作只引用了参数值,并不会对实参进行操作。除非使用&传递 先声明, 阅读全文
posted @ 2026-05-10 17:03
www6526
阅读(8)
评论(0)
推荐(0)
摘要:
数组特点 1.连续内存空间 2.每个元素都是相同数据类型 申请方式示例 1.int arr[5] 2.int arr[5] = {1,2,3,,4,5} 自动用0填补剩余未指定值 3.int arr[] = {1,2,3,4,5} 自动数组长度为4 基础操作 sizeof(arr) 数组在内存中长度 阅读全文
posted @ 2026-05-09 19:26
www6526
阅读(9)
评论(0)
推荐(0)
浙公网安备 33010602011771号