自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(16)
  • 收藏
  • 关注

原创 c++学习心得(八)空指针和野指针

空指针:用于给指针变量进行初始化int *p = NULL;但是空指针不可以进行访问,这是因为0~255之间的内存编号是系统占用的内存,不允许系统访问。野指针用于指向非法内存空间。int *p = (int*)0x1100;在程序中,避免进行野指针。综上空指针,野指针我们都没有访问权限,我们不应该访问他们。...

2021-07-07 00:00:02 146 2

原创 c++学习心得(七)指针变量

首先,可以通过指针来保存一个地址,或者说指针就是一个地址int a = 10;int *p;p = &a;&为取地址符,&a为获取a的地址,此时指针p指向a的地址,需要注意的是p指向的是a的地址,而*p是访问占有a的地址的变量,可以通过*p在访问变量a的同时修改变量a的值。int a = 10;int *p;p = &a;*p = 1000;#include <iostream>#include <string>#i

2021-07-06 02:43:41 101

原创 c++学习心得(七)函数的分文件编写

函数的分文件编写1.创建后缀名为.h的头文件:在解决方案中找到头文件右键选择新建项2.创建后缀名为.cpp的源文件在解决方案中找到源文件右键选择新建项3.在头文件中写函数的声明以及函数自带的头文件如:#include <iostream>#include <string>#include <iostream>#include <string>using namespace std;void swap(int a,

2021-07-04 14:19:06 56

原创 c++学习心得(七)函数

#include <iostream>#include <string>using namespace std;/* 返回值类型 函数名(参数列表){ 函数体语句 return表达式}*///如果函数不需要返回值,声明的时候可以用voidvoid swap(int nu1,int nu2){ int temp = 0; temp = nu1; nu1 = nu2; nu2 = temp; cout << nu1 << n.

2021-07-04 14:02:26 110

原创 c++学习心得(六) 数组(5)二维数组应用案例输出成绩

#include <iostream>#include <string>using namespace std;int main(){ int scores[3][3] = { {100,100,100}, {90,50,100}, {60,70,80} }; cout << " 语文 " << "数学 " << "英语 " << endl; for (int i = 0; i.

2021-06-30 17:50:25 98

原创 c++学习心得(六) 数组(6)二维数组名

#include <iostream>#include <string>using namespace std;int main(){ //二维数组名称用途 //1.可以查看占用内存空间大小 int arr[2][3] = { {1, 2, 3}, {4, 5, 6} }; cout << "二维数组占用内存空间为:" << sizeof(arr) << endl; //2.可以查看二维数组首地址 cout .

2021-06-30 17:31:46 67

原创 c++学习心得(六) 数组(5)二维数组定义方法

#include <iostream>#include <string>using namespace std;int main(){ //二维数组 /*定义方式 1.数据类型 数组名[ 行数 ][ 列数 ]; 2.数据类型 数组名[ 行数 ][ 列数 ] = { {数据1,数据2} , {数据3, 数据4 } }; 3.数据类型 数组名[ 行数 ][ 列数 ] = {数据1,数据2,数据3,数据4}; 1.数据类型 数组名[ ][ 列数 ] = { .

2021-06-28 22:08:26 117 2

原创 c++学习心得(六) 数组(4)冒泡排序法

冒泡排序法#include <iostream>#include <string>using namespace std;int main(){ //冒泡排序 int a[9] = {4,2,8,0,5,7,1,3,9}; //初始化数组 int temp = 0; //用于交换变量值时的中间媒介 for (int i = 8 ; i>0 ; i-- ) //外层循环 { fo

2021-06-27 21:24:59 160 1

原创 c++学习心得(六) 数组(3)五只小猪称体重

#include <iostream>#include <string>using namespace std;int main(){ //找出最重的小猪 int arr[5] = { 300, 350,200,400,250 }; int a = 0; for (int i = 1; i < 5; i++) { if (arr[a] < arr[i]) { a = i; } } cout << "最重的小猪为" .

2021-06-21 20:18:27 128

原创 c++学习心得(六) 数组(2)

一维数组名称用途:1.可以统计整个数组在内存中的长度,用siazof(a)即可。#include <iostream>#include <string>using namespace std;int main(){ int arr[5] = {}; //统计数组在内存空间的长度 cout << sizeof(arr) << endl; //统计数组中的某一个样本在内存中所占的空间 cout << sizeof(arr[

2021-06-21 20:08:31 66

原创 c++学习心得(六) 数组(1)

数组特点:1.放在一块连续的内存空间中2.数组中每个元素都是相同的数据类型#include <iostream>#include <string>using namespace std;int main(){ //*数组定义方式 //1.数据类型 数组名[数组长度]; int arr[5]; // 创建数组 arr[0] = 10;//给数组赋值 arr[1] = 20; arr[2] = 30; arr[3] = 40; arr[4] = 5

2021-06-21 19:45:26 246

原创 c++学习心得(五)break与continue的区别 和goto语句

break简单来说就是跳出循环,continue为跳出单次循环,执行下一次循环break:#include <iostream>#include <string>using namespace std;int main(){ // break 使用时机 //case 语句中cout << "请选择游戏难度" << endl; cout << "1、梦魇" << endl; cout << "2、

2021-06-19 12:17:28 74

原创 c++学习心得(四) 九九乘法口诀案例

要求:运用嵌套循环打印九九乘法表我的实现方式比较复杂,具体实现方法如下#include <iostream>#include <string>using namespace std;int main(){ //利用嵌套循环实现九九乘法表 int a = 1; //起始1 int b = 1; //起始1 int m = 0; //为了每行都能从1开始打印所定义的中间变量 int c = 0; //保

2021-06-15 16:05:22 171

原创 c++学习心得(三)敲桌子案例

#include <iostream>#include <string>using namespace std;int main(){ int num = 0; for (int i = 1; i < 100; i++) { if ((i % 7 == 0) || (i % 10 == 7) || (i / 10 == 7)) { num = i; cout << num << endl; } } syste.

2021-06-14 20:14:35 46

原创 c++学习心得(二) 设计一段代码计算出所有三位数中的水仙花数

#include <iostream>#include <string>using namespace std;int main(){ int num = 100; int a = 0; //个位 int b = 0; //十位 int c = 0; //百位 int sxh = 0; //水仙花数 do { a = num % 10; b = num / 10 % 10; c = num / 100; if (((a * a * a) + .

2021-06-14 19:58:14 183

原创 c++学习心得(一)一个猜数字大小的小游戏

#include<iostream>using namespace std;//time系统时间头文件包含#include <ctime>int main1() { //添加随机数种子 作用利用当前系统时间生成随机数,防止每次随机数一样 srand((unsigned int)time(NULL)); int num = rand() % 100;//随机生成0-99随机数 int a = 0; cout << "请输入一...

2021-06-14 19:14:22 311 2

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除