随笔分类 - C++
摘要:#include <iostream> using namespace std; //学生结构体 struct Student { //姓名 string sName; //分数 int score; }; //老师的结构体 struct Teacher { //姓名 string tname; /
阅读全文
摘要:#include <iostream> using namespace std; //const 的使用场景 //定义学生结构体 struct student { //姓名 string name; //年龄 int age; //分数 int score; }; //将函数中的形参改为指针,可以减
阅读全文
摘要:#include <iostream> using namespace std; //定义学生结构体 struct student { //姓名 string name; //年龄 int age; //分数 int score; }; //打印学生函数 //1.值传递 void printstud
阅读全文
摘要:#include <iostream> using namespace std; //定义学生结构体 struct student { string name; int age; int score; }; //定义老师结构体 struct teacher { int id; string name
阅读全文
摘要:#include <iostream> using namespace std; //结构体指针 //定义学生结构体 struct Student { //姓名 string name; //年龄 int age; //分数 int score; }; int main() { //1.创建学生结构
阅读全文
摘要:#include <iostream> using namespace std; //1.定义结构体 struct Student { //姓名 string name; //年龄 int age; //分数 int score; }; int main() { //2.创建结构体数组 Studen
阅读全文
摘要:#include <iostream> using namespace std; //1.创建学生数据类型:学生包括(姓名,年龄,分数) //自定义数据类型,一些类型集合组成的一个类型 //语法 struct 类型名称{成员列表} struct Student { //成员列表 //姓名 strin
阅读全文
摘要:#include <iostream> using namespace std; //冒泡排序函数 void bubblesort(int* arr, int len) { for (size_t i = 0; i < len - 1; i++) { //内层循环对比 次数=元素个数-当前轮数-1
阅读全文
摘要:#include <iostream> using namespace std; void swap01(int a, int b) { int temp = a; a = b; b = temp; cout << "swap01中a=" << a << endl; cout << "swap01中
阅读全文
摘要:#include <iostream> using namespace std; int main() {//指针和数组 //利用指针访问数组中的元素 int arr[10] = { 1,2,3,4,5,6,7,8,9,10 }; cout << "第一个元素为:" << arr[0] << end
阅读全文
摘要:#include <iostream> using namespace std; int main() { //1.const修饰指针-常量指针 int a = 10; int b = 10; const int* p = &a; //指针指向的值不可以改,指针指向可以改 //*p=20;错误 p
阅读全文
摘要:#include <iostream> using namespace std; int main() { //野指针 //在程序中避免出现野指针 int* p = (int*)0x1100; cout << *p << endl;//报错 system("pause"); return 0; }
阅读全文
摘要:#include <iostream> using namespace std; int main() { //空指针 //1.空指针用于给指针变量进行初始化 int* p = NULL; //2.空指针不可以进行访问 //0`255之间的内存编号是系统占用,不允许访问 //*p = 1000;//
阅读全文
摘要:#include <iostream> using namespace std; int main() { //指针所占用的内存空间大小 int a = 10; int* p = &a; //32位操作系统,指针占用4个字节空间大小,不管什么数据类型 //64位操作系统,指针占用8个字节空间大小;
阅读全文
摘要:#include <iostream> using namespace std; int main() { //1.定义指针 int a = 10; //指针定义的语法:数据类型*指针变量名; int* p; //让指针记录变量a的地址 p = &a; cout << "a的地址为:\t" << &
阅读全文
摘要:1.创建后缀名为.h的头文件,在头文件中写函数声明 //头文件 swap.h #include<iostream> using namespace std; //函数的声明 void swap(int a, int b); 2.创建后缀名为.cpp的源文件,在源文件中写函数定义 //源文件 swap
阅读全文
摘要:#include <iostream> using namespace std; //提前告诉编译器函数的存在,可利用函数的声明 //函数的声明 //声明可以写多次,定义只能一次 int max(int a, int b); int main() { cout << max(100, 600) <<
阅读全文
摘要:#include <iostream> using namespace std; //函数常见样式 //1.无参无返 void test01() { cout << "test01" << endl; } //2.有参无返 void test02(int a) { cout << "test02"
阅读全文
摘要:#include <iostream> using namespace std; //值传递 //定义函数,实现两个数字进行交换函数 //如果函数不需要返回值,声明的时候可以写void; void swap(int num1, int num2) { cout << "交换前:" << endl;
阅读全文
摘要:#include <iostream> using namespace std; //定义加法函数 //没有数据,叫形参 int add(int num1, int num2) { return num1 + num2; } int main() { //main函数中调用add函数 int a =
阅读全文

浙公网安备 33010602011771号