摘要: #include <iostream> using namespace std; int main() {//指针和数组 //利用指针访问数组中的元素 int arr[10] = { 1,2,3,4,5,6,7,8,9,10 }; cout << "第一个元素为:" << arr[0] << end 阅读全文
posted @ 2021-09-04 15:24 梦之心 阅读(26) 评论(0) 推荐(0) 编辑
摘要: #include <iostream> using namespace std; int main() { //1.const修饰指针-常量指针 int a = 10; int b = 10; const int* p = &a; //指针指向的值不可以改,指针指向可以改 //*p=20;错误 p 阅读全文
posted @ 2021-09-04 15:16 梦之心 阅读(25) 评论(0) 推荐(0) 编辑
摘要: #include <iostream> using namespace std; int main() { //野指针 //在程序中避免出现野指针 int* p = (int*)0x1100; cout << *p << endl;//报错 system("pause"); return 0; } 阅读全文
posted @ 2021-09-04 14:31 梦之心 阅读(30) 评论(0) 推荐(0) 编辑
摘要: #include <iostream> using namespace std; int main() { //空指针 //1.空指针用于给指针变量进行初始化 int* p = NULL; //2.空指针不可以进行访问 //0`255之间的内存编号是系统占用,不允许访问 //*p = 1000;// 阅读全文
posted @ 2021-09-04 14:23 梦之心 阅读(56) 评论(0) 推荐(0) 编辑
摘要: #include <iostream> using namespace std; int main() { //指针所占用的内存空间大小 int a = 10; int* p = &a; //32位操作系统,指针占用4个字节空间大小,不管什么数据类型 //64位操作系统,指针占用8个字节空间大小; 阅读全文
posted @ 2021-09-04 14:21 梦之心 阅读(271) 评论(0) 推荐(0) 编辑
摘要: #include <iostream> using namespace std; int main() { //1.定义指针 int a = 10; //指针定义的语法:数据类型*指针变量名; int* p; //让指针记录变量a的地址 p = &a; cout << "a的地址为:\t" << & 阅读全文
posted @ 2021-09-04 14:11 梦之心 阅读(216) 评论(0) 推荐(0) 编辑
摘要: 1.创建后缀名为.h的头文件,在头文件中写函数声明 //头文件 swap.h #include<iostream> using namespace std; //函数的声明 void swap(int a, int b); 2.创建后缀名为.cpp的源文件,在源文件中写函数定义 //源文件 swap 阅读全文
posted @ 2021-09-04 14:01 梦之心 阅读(84) 评论(0) 推荐(0) 编辑
摘要: #include <iostream> using namespace std; //提前告诉编译器函数的存在,可利用函数的声明 //函数的声明 //声明可以写多次,定义只能一次 int max(int a, int b); int main() { cout << max(100, 600) << 阅读全文
posted @ 2021-09-04 13:46 梦之心 阅读(43) 评论(0) 推荐(0) 编辑
摘要: #include <iostream> using namespace std; //函数常见样式 //1.无参无返 void test01() { cout << "test01" << endl; } //2.有参无返 void test02(int a) { cout << "test02" 阅读全文
posted @ 2021-09-04 13:43 梦之心 阅读(29) 评论(0) 推荐(0) 编辑
摘要: #include <iostream> using namespace std; //值传递 //定义函数,实现两个数字进行交换函数 //如果函数不需要返回值,声明的时候可以写void; void swap(int num1, int num2) { cout << "交换前:" << endl; 阅读全文
posted @ 2021-09-04 13:40 梦之心 阅读(35) 评论(0) 推荐(0) 编辑
摘要: #include <iostream> using namespace std; //定义加法函数 //没有数据,叫形参 int add(int num1, int num2) { return num1 + num2; } int main() { //main函数中调用add函数 int a = 阅读全文
posted @ 2021-09-04 13:38 梦之心 阅读(58) 评论(0) 推荐(0) 编辑
摘要: #include <iostream> using namespace std; //函数定义 //语法 //返回值类型 函数名 (参数列表) //{ //函数语句 //return表达式 //} int add(int num1, int num2) { int sum = num1 + num2 阅读全文
posted @ 2021-09-04 13:30 梦之心 阅读(35) 评论(0) 推荐(0) 编辑
摘要: #include <iostream> using namespace std; int main() { //二维数组案例-考试成绩统计 //1.创建二维数组 int scores[3][3] = { {100,100,100}, {90,50,100}, {60,70,80} }; string 阅读全文
posted @ 2021-09-04 13:21 梦之心 阅读(120) 评论(0) 推荐(0) 编辑
摘要: #include <iostream> #include<string> using namespace std; int main() { //二维数组名称用法 int arr[2][3] = { {1,2,3,}, {4,5,6} }; cout << "二维数组占用内存空间为:" << siz 阅读全文
posted @ 2021-09-04 13:20 梦之心 阅读(106) 评论(0) 推荐(0) 编辑
摘要: #include <iostream> using namespace std; int main() { //二维数组定义 /* 1.数据类型 数组名[行数][列数]; 2.数据类型 数组名[行数][列数]={{数据1,数据2},{数据2=3,数据4}}; 3.数据类型 数组名[行数][列数]={ 阅读全文
posted @ 2021-09-04 13:17 梦之心 阅读(152) 评论(0) 推荐(0) 编辑
摘要: #include <iostream> using namespace std; int main() { int arr[] = { 4,2,8,0,5,7,1,3,9 ,15,17,14 }; cout << "排序前" << endl; for (size_t i = 0; i < (size 阅读全文
posted @ 2021-09-04 11:28 梦之心 阅读(65) 评论(0) 推荐(0) 编辑
摘要: #include <iostream> using namespace std; int main() { //实现数组元素逆置 //1.创建数组 int arr[] = { 1,2,3,4,5,6 }; cout << "逆置前数组" << endl; for (size_t i = 0; i < 阅读全文
posted @ 2021-09-04 11:23 梦之心 阅读(254) 评论(0) 推荐(0) 编辑
摘要: #include <iostream> using namespace std; int main() { //创建5只小猪体重 int arr[] = { 300,350,200,400,250,100,50 }; int max = 0;//设置一个最大值 //从数组中找到最大的 for (si 阅读全文
posted @ 2021-09-04 10:52 梦之心 阅读(87) 评论(0) 推荐(0) 编辑
摘要: #include <iostream> using namespace std; int main() { //数组名用途 //1.可以通过数组名统计整个数组占用的内存大小 int arr[] = { 1,2,3,4,5,6,7,8,9,10 }; cout << "整个数组占用的内存空间为;" < 阅读全文
posted @ 2021-09-04 10:40 梦之心 阅读(45) 评论(0) 推荐(0) 编辑
摘要: #include <iostream> using namespace std; int main() { //数组 //1.数据类型 数组名[数组长度]; //2.数据类型 数组名[数组长度]={值1.值2...}; //3.数据类型 数组名[]= {值1.值2...}; //1.数据类型 数组名 阅读全文
posted @ 2021-09-04 09:52 梦之心 阅读(144) 评论(0) 推荐(0) 编辑
摘要: #include <iostream> using namespace std; int main() { //goto语句 cout << "1.xxxxxxxxxx" << endl; cout << "2.xxxxxxxxxx" << endl; goto AA;//跳转到标记 cout << 阅读全文
posted @ 2021-09-04 09:44 梦之心 阅读(40) 评论(0) 推荐(0) 编辑
摘要: #include <iostream> using namespace std; int main() { for (size_t i = 0; i < 100; i++) { //如果是奇数输出,偶数不输出 if (i % 2 == 0) { continue;//到此为止不在执行,执行下次循环 阅读全文
posted @ 2021-09-04 09:34 梦之心 阅读(46) 评论(0) 推荐(0) 编辑
摘要: #include <iostream> using namespace std; int main() { //break使用 //1.switch语句中; cout << "选择副本难度" << endl; cout << "1.普通" << endl; cout << "2.中等" << end 阅读全文
posted @ 2021-09-04 09:32 梦之心 阅读(41) 评论(0) 推荐(0) 编辑
摘要: #include <iostream> using namespace std; int main() { //乘法口诀表 //1×1 = 1 //1×2 = 2 2×2 = 4 //1×3 = 3 2×3 = 6 3×3 = 9 //1×4 = 4 2×4 = 8 3×4 = 12 4×4 = 1 阅读全文
posted @ 2021-09-04 09:26 梦之心 阅读(74) 评论(0) 推荐(0) 编辑
摘要: #include <iostream> using namespace std; int main() { //利用嵌套循环打印星图 //外层循环,外执行一次,内执行一轮 for (int i = 0; i < 10; i++) { //内层循环 for (int j = 0; j < 10; j+ 阅读全文
posted @ 2021-09-04 09:12 梦之心 阅读(37) 评论(0) 推荐(0) 编辑
摘要: #include <iostream> using namespace std; int main() { //敲桌子 //输出1-100; for (int i = 1; i <= 100; i++) { //从100个数字找到特殊数字,打印敲桌子 //如果是7的倍数,个位,十位有7,打印敲桌子 阅读全文
posted @ 2021-09-04 09:10 梦之心 阅读(40) 评论(0) 推荐(0) 编辑
摘要: #include <iostream> using namespace std; int main() { //for循环 //从数字0打印数字9 for (int i = 0; i < 10; i++) { cout << i << endl; } system("pause"); return 阅读全文
posted @ 2021-09-04 09:04 梦之心 阅读(40) 评论(0) 推荐(0) 编辑
摘要: #include <iostream> using namespace std; int main() { //1.打印所有的三位数字 int num = 100; do {//2.从所有三位数字找到水仙花数 int a = 0; int b = 0; int c = 0; int d = 0; a 阅读全文
posted @ 2021-09-04 09:00 梦之心 阅读(135) 评论(0) 推荐(0) 编辑
摘要: #include <iostream> using namespace std; int main() { //do...while语句 //在屏幕中输出0到9这10个数字 int num = 0; do { cout << num << endl; num++; } while (num < 10 阅读全文
posted @ 2021-09-04 08:46 梦之心 阅读(33) 评论(0) 推荐(0) 编辑
摘要: #include <iostream> #include <time.h> using namespace std; int main() { //生成随机数 //添加随机数种子,作用利用当前系统时间生成随机数,防止每次随机数都一样 srand((unsigned int)time(NULL)); 阅读全文
posted @ 2021-09-04 08:32 梦之心 阅读(35) 评论(0) 推荐(0) 编辑
摘要: #include <iostream> using namespace std; int main() { //while语句 //屏幕打印0-9,这10个数字 //避免死循环 int i = 0; while (i<10) { cout << i<< endl; i++; } system("pa 阅读全文
posted @ 2021-09-04 08:20 梦之心 阅读(32) 评论(0) 推荐(0) 编辑
摘要: #include <iostream> using namespace std; int main() { //switch语句 //给一个电影打分 int fen; cout << "清输入一个分数" << endl; cin >>fen; cout <<"你输入的是"<< fen <<"分"<< 阅读全文
posted @ 2021-09-04 08:16 梦之心 阅读(40) 评论(0) 推荐(0) 编辑
摘要: #include <iostream> using namespace std; int main() { //三目运算符 //创建三个变量A B C //A和B比较,将变量大得赋值变量C int a = 10; int b = 20; int c = 0; c = (a > b ? a : b); 阅读全文
posted @ 2021-09-04 08:12 梦之心 阅读(28) 评论(0) 推荐(0) 编辑
摘要: #include <iostream> using namespace std; int main() { //三只小猪秤体重 //先判断A和B谁重 //A重 让A和C比较 //A重 结果时A重 //C重 结果时C重 //B重 让B和C比较 //B重 结果时B重 //C重 结果时C重 int num 阅读全文
posted @ 2021-09-04 08:05 梦之心 阅读(131) 评论(0) 推荐(0) 编辑
摘要: #include <iostream> using namespace std; int main() { //选择结构 单行if语句 //用户输入分数,如果分数大于600,视为考上一本大学,在屏幕上输出 //1.用户输入分数 int scroe = 0; cout << "请输入一个分数:" << 阅读全文
posted @ 2021-09-04 07:52 梦之心 阅读(71) 评论(0) 推荐(0) 编辑
摘要: #include <iostream> using namespace std; int main() { //选择结构 多条件if语句 //输入一个考试分数,如果大于600分,视为考上一本大学,在屏幕输出 //大于500,视为二本大学,在屏幕输出 //大于400,视为三本大学,在屏幕输出 //小于 阅读全文
posted @ 2021-09-04 07:42 梦之心 阅读(40) 评论(0) 推荐(0) 编辑
摘要: #include <iostream> using namespace std; int main() { //选择结构 多行if语句 //用户输入分数,如果分数大于600,视为考上一本大学,在屏幕上输出, //如果没考上,打印未考上 //用户输入分数 int score = 0; cout << 阅读全文
posted @ 2021-09-03 19:46 梦之心 阅读(39) 评论(0) 推荐(0) 编辑
摘要: #include <iostream> using namespace std; int main() { //选择结构 单行if语句 //用户输入分数,如果分数大于600,视为考上一本大学,在屏幕上输出 //1.用户输入分数 int scroe = 0; cout << "请输入一个分数:" << 阅读全文
posted @ 2021-09-03 19:44 梦之心 阅读(49) 评论(0) 推荐(0) 编辑
摘要: #include <iostream> using namespace std; int main() { //逻辑运算符 或 ||,同假为假,其余为真 int a = 10; int b = 10; cout << (a || b) << endl;//结果真 a = 0; b = 10; cou 阅读全文
posted @ 2021-09-03 19:34 梦之心 阅读(52) 评论(0) 推荐(0) 编辑
摘要: #include <iostream> using namespace std; int main() { //逻辑运算符 与 && 同真为真,其余为假 int a = 10; int b = 10; cout << (a&&b)<< endl;//都真 a = 0; b = 10; cout << 阅读全文
posted @ 2021-09-03 18:00 梦之心 阅读(41) 评论(0) 推荐(0) 编辑