摘要: #include <iostream> #include <string> using namespace std; //定义学生结构体 struct Student { //定义成员列表 string name; int age; int score; }; //值传递 void printStu 阅读全文
posted @ 2025-07-05 16:46 little小新 阅读(2) 评论(0) 推荐(0)
摘要: 将结构体作参数传入函数中 #include <iostream> #include <string> using namespace std; //定义学生结构体 struct Student { //定义成员列表 string name; int age; int score; }; //值传递 阅读全文
posted @ 2025-07-05 16:33 little小新 阅读(1) 评论(0) 推荐(0)
摘要: #include <iostream> #include <string> using namespace std; //定义学生结构体 struct Student { //定义成员列表 string name; int age; int score; }; //定义老师结构体 struct te 阅读全文
posted @ 2025-07-05 16:19 little小新 阅读(1) 评论(0) 推荐(0)
摘要: #include <iostream> #include <string> using namespace std; //定义结构体 struct Student { //定义成员列表 string name; int age; int score; }; int main() { //声明结构体变 阅读全文
posted @ 2025-07-05 16:08 little小新 阅读(2) 评论(0) 推荐(0)
摘要: 案例描述:封装一个函数,利用冒泡排序,实现对整型数组的升序排序 #include <iostream> using namespace std; //冒泡排序函数 void bubbleSort(int* arr, int len) { for (int i = 0; i < len - 1; i+ 阅读全文
posted @ 2025-06-28 16:53 little小新 阅读(2) 评论(0) 推荐(0)
摘要: #include <iostream> using namespace std; //值传递(不能改变实参a与b的值) void swap0(int a, int b) { //交换值 int temp = a; a = b; b = a; cout << "swap0 a = " << a << 阅读全文
posted @ 2025-06-28 16:28 little小新 阅读(3) 评论(0) 推荐(0)
摘要: 利用指针访问数组元素 #include <iostream> using namespace std; int main() { int arr[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; cout << "第一个元素为:" << arr[0] << endl; 阅读全文
posted @ 2025-06-28 16:12 little小新 阅读(0) 评论(0) 推荐(0)
摘要: 1.常量指针 const int* p = &a; 特点:指针的指向可以修改,但是指针指向的指针不可以修改 如:*p = 20是错误的值不能修改 但:*p = &b;是可以的,重新指向其它的地址 2.指针常量 int* const p = &a; 特点:指针的指向不可以修改,指针指向的值可以修改 如 阅读全文
posted @ 2025-06-28 16:00 little小新 阅读(4) 评论(0) 推荐(0)
摘要: #include <iostream> using namespace std; int main() { //1.指针得定义 int a = 10; //定义整型变量a //指针定义语法: 数据类型 * 变量名 int* p; //指针变量赋值 p = &a; //指针指向变量a得地址(0xxff 阅读全文
posted @ 2025-06-28 12:46 little小新 阅读(0) 评论(0) 推荐(0)
摘要: 函数的文件编写一般有4个步骤: 1.创建后缀名为.h的头文件 2.创建后缀名为.cpp的源文件 3.再头文件中写函数的声明 4.在源文件中写函数的定义 1.创建头文件swap.h #include <iostream> using namespace std; //函数的声明 void swap(i 阅读全文
posted @ 2025-06-26 23:04 little小新 阅读(2) 评论(0) 推荐(0)