当前位置: 首页 > news >正文

怎么网站是什么语言做的常州seo关键词排名

怎么网站是什么语言做的,常州seo关键词排名,重庆工程建设信息网站,生成器c基础学习第三天(指针,结构体) 文章目录 1、指针1.1、指针的基本概念1.2、指针变量的定义和使用1.3、 指针所占内存空间1.4、空指针和野指针1.5、 const修饰指针1.5.1、const修饰指针-常量指针1.5.2、const修饰常量-指针常量1.5.3、const即修…

c++基础学习第三天(指针,结构体)

文章目录

  • 1、指针
    • 1.1、指针的基本概念
    • 1.2、指针变量的定义和使用
    • 1.3、 指针所占内存空间
    • 1.4、空指针和野指针
    • 1.5、 const修饰指针
      • 1.5.1、const修饰指针-常量指针
      • 1.5.2、const修饰常量-指针常量
      • 1.5.3、const即修饰指针,又修饰常量
  • 2、结构体
    • 2.1、结构体基本概念
    • 2.2、结构体定义和使用
    • 2.3、结构体数组
    • 2.4、结构体指针
    • 2.5、结构体嵌套结构体
    • 2.6、结构体做函数参数
    • 2.7、结构体中const使用场景


1、指针

1.1、指针的基本概念

指针的作用:可以通过指针间接访问内存

  • 内存编号是从0开始记录的,一般用十六进制数字表示
  • 可以利用指针变量保存地址

1.2、指针变量的定义和使用

指针变量定义语法:*数据类型 变量名;

//1、定义指针
int a1 = 10;
// 指针定义的语法:数据类型 * 指针变量名:
int *p;
// 让指针记录变量a的地址
p = &a1;
cout << "a的地址为:" << &a1 << endl;
cout << "指针p为:" << p << endl;
//2、使用指针
//可以通过解引用的方式来找到指针指向的内存,查看内存内容。
//指针前加 * 代表解引用,找到指针指向的内存中的数据
*p = 1000;
cout << "a1 = " << a1 << endl;
cout << "*p=" << *p << endl;

1.3、 指针所占内存空间

提问:指针也是种数据类型,那么这种数据类型占用多少内存空间?

在32位操作系统下:占用4个字节空间,64位下占8个字节。不管是什么数据类型

//指针所占内存空间
int a2 = 10;
//int p;
//p=&a:
int *p1 = &a2;
//在32位操作系统下,指针是占4个字节空间大小,***不管是什么数据类型***
//在64位操作系统下,指针是占8个字节空间大小
cout << "sizeof(int*)=" << sizeof(int*) << endl;
cout << "sizeof (float*)=" << sizeof(float*) << endl;
cout << "sizeof (double*)=" << sizeof(double*) << endl;
cout << "sizeof(char*)="<< sizeof(char*) << endl;

1.4、空指针和野指针

空指针:指针变量指向内存中编号为0的空间
用途:初始化指针变量
注意:空指针指向的内存是不可以访问的

空指针

//1、空指针用于给指针变量进行初始化
int *p4 =  NULL;
// 2、空指针(0号内存空间)是不可以进行访问的
//0~255之间的内存编号是系统占用的,因此不可以访问
//*p = 100;

野指针:指针变量指向非法的内存空间(不是自己申请的内存空间)

/野指针
//在程序中,尽量避免出现野指针
int *p = (int*)0x1100;
cout << * p << endl;

总结:空指针和野指针都不是我们申请的空间,因此不要访问。

1.5、 const修饰指针

const修饰指针有三种情况:

1.5.1、const修饰指针-常量指针

const int *p=&a:

常量指针
特点:指针的指向可以修改,但是指针指向的值不可以改
*p=20;错误,指针指向的值不可以改
p=&b;正确,指针指向可以改

1.5.2、const修饰常量-指针常量

int * const p=&a:

指针常量
特点:指针的指向不可以改,指针指向的值可以改
*p=20;正确,指向的值可以改
p=&b;错误,指针指句不可以改

1.5.3、const即修饰指针,又修饰常量

const int * const p =a;

特点:指针的指向和指针指向的值都不可以改
*p=20;/错误
p=&b;/错误

//1、const修饰指针   常量(const)指针(*)
int a4 = 10;
int b4 = 10;
const int * p7 = &a4;
//指针指向的值(*P)不可以改,指针的指向(p)可以改
//*p=20:错误
p7 = &b4;//正确//2、const修饰常量 指针(*)常量(const)
//指针的指向(p2)不可以改,指针指向的值(*p2)可以改
int * const p5 = &a4;
*p5 = 100; // 正确的
//p2=&b:/错误,指针的指向不可以改// 3、const修饰指针和常量
const int * const p6 = &a4;
//指针的指向和指针指向的值都不可以改
//*p3=100;//错误
//b3 = &b; //错误

2、结构体

2.1、结构体基本概念

结构体属于用户自定义的数据类型,允许用户存储不同的数据类型

2.2、结构体定义和使用

语法:struct 结构体名 {结构体成员列表};
通过结构体创建变最的方式有三种:

  • struct 结构体名 变量名
  • struct 结构体名 变量名={成员1值,成员2值…}
  • 定义结构体时便创建变星

通过学生类型创建具体学生

//2.1 struct Student sl
struct Student s1;
//给s1属性赋值,通过.访问结构体变量中的属性
s1.name = "张三";
s1.age = 18;
s1.score = 100;
cout << "姓名:" << s1.name << "  年龄:" << s1.age << "  分数:" << s1.score << endl;
//2.2 struct Student s2 ={..};
struct Student s2 = { "李四",19,80 };
cout << "姓名:" << s2.name << "  年龄:" << s2.age << "  分数:" << s2.score << endl;
//2.3在定义结构体时顺便创建结构体变量
struct Student1 {//成员列表// 姓名string name;// 年龄int age;//分数int score;
}s3;s3.name = "王五";
s3.age = 20;
s3.score = 60;
cout << "姓名:" << s3.name << "  年龄:" << s3.age << "  分数:" << s3.score << endl;

struct关键字可以省略(创建变量时),定义时struct关键字不可以省略。
总结1:定义结构体时的关键字是struct,不可省略
总结2:创建结构体变是时,关键字structi可以省略
总结3:结构体变量利用操作符"."访门成员

2.3、结构体数组

作用:将自定义的结构体放入到数组中方便维护
语法:struct 结构体名 数组名[元素个数]={{},{},·{}};

//1、创建结构体数组
struct Student stuArray[3]{{"张三",18,100},{"李四",28, 99},{ "王五",38,66}
};
// 2、给结构体数组中的元素赋值
stuArray[2].name = "赵六";
stuArray[2].age = 80;
stuArray[2].score = 60;
// 3、遍历结构体数组
for (int i = 0; i < 3; i++) {cout<< "姓名:"<<stuArray[i].name<<"年龄:"<<stuArray[i].age<< "分数:"<< stuArray[i].score<< endl;
}

2.4、结构体指针

作用:通过指针访问结构体中的成员
利用操作符->可以通过结构体指针访问结构体属性

//1、创建学生结构体变量
struct Student s = { "张三",18,100};
//2、通过指针指向结构体变量
struct Student *p =&s;
//3、通过指针访问结构体变量中的数据
cout << "姓名:" << p->name << "年龄:" << p->age << "分数:" << p->score << endl;

2.5、结构体嵌套结构体

作用:结构体中的成员可以是另一个结构体
例如:每个老师辅导一个学员,一个老师的结构体中,记录一个学生的结构体

//定义学生结构体
struct student{string name; // 姓名int age;//年龄int score; // 分数
};//定义老师结构体
struct teacher {int id;//教师编号string name; // 教师姓名int age;//年龄struct student stu;//辅导的学生
};//结构体嵌套结构体
//创建老师
struct teacher t;
t.id = 10000;
t.name = "老王";
t.age = 50;
t.stu.name = "小王";
t.stu.age = 20;
t.stu.score = 60;
cout << "老师姓名:" << t.name << "老师编号:" << t.id << "老师年龄:" << t.age<< "老师辅导的学生姓名:" << t.stu.name << "学生年龄:" << t.stu.age<< "学生考试分数为:" << t.stu.score<<endl;

2.6、结构体做函数参数

作用:将结构体作为参数向函数中传递
传递方式有两种:

  • 值传递
  • 地址传递

总结:如果不想修改主函数中的数据,用值传递反之用地址传递

2.7、结构体中const使用场景

作用:用const来防止误操作

将函数中的形参改为指针,可以减少内存空间,而且不会复制新的副本出来
void printStudents(const student *s)防止函数修改属性值
指针(地址传递)节省空间,值传递会复制一份给函数内的变量。


文章转载自:
http://dunedin.bfmq.cn
http://friedcake.bfmq.cn
http://puckish.bfmq.cn
http://agin.bfmq.cn
http://spaniel.bfmq.cn
http://trailbreaker.bfmq.cn
http://capricious.bfmq.cn
http://omnicompetent.bfmq.cn
http://infractor.bfmq.cn
http://zyzzyva.bfmq.cn
http://coricidin.bfmq.cn
http://churrigueresque.bfmq.cn
http://bondieuserie.bfmq.cn
http://conciliarism.bfmq.cn
http://gluepot.bfmq.cn
http://jesuitic.bfmq.cn
http://elocutionist.bfmq.cn
http://lycanthrope.bfmq.cn
http://chairwarmer.bfmq.cn
http://reincarnationist.bfmq.cn
http://encourage.bfmq.cn
http://millwork.bfmq.cn
http://souzalite.bfmq.cn
http://reconvict.bfmq.cn
http://quarreller.bfmq.cn
http://stormward.bfmq.cn
http://lockpicker.bfmq.cn
http://crownwork.bfmq.cn
http://biryani.bfmq.cn
http://milchig.bfmq.cn
http://sina.bfmq.cn
http://autographical.bfmq.cn
http://swimmy.bfmq.cn
http://serigraph.bfmq.cn
http://bipinnate.bfmq.cn
http://dalapon.bfmq.cn
http://cystectomy.bfmq.cn
http://stable.bfmq.cn
http://curvesome.bfmq.cn
http://tshi.bfmq.cn
http://incendive.bfmq.cn
http://downhill.bfmq.cn
http://waiter.bfmq.cn
http://explicate.bfmq.cn
http://zoogenous.bfmq.cn
http://urolith.bfmq.cn
http://supermarket.bfmq.cn
http://southampton.bfmq.cn
http://haemorrhoids.bfmq.cn
http://preheating.bfmq.cn
http://sian.bfmq.cn
http://born.bfmq.cn
http://oracy.bfmq.cn
http://agranulocytosis.bfmq.cn
http://thinker.bfmq.cn
http://encrimson.bfmq.cn
http://populism.bfmq.cn
http://bioclimatic.bfmq.cn
http://scandent.bfmq.cn
http://anticompetitive.bfmq.cn
http://ruff.bfmq.cn
http://uncinariasis.bfmq.cn
http://oolite.bfmq.cn
http://cocotte.bfmq.cn
http://mandi.bfmq.cn
http://fundamentalism.bfmq.cn
http://trappist.bfmq.cn
http://priggism.bfmq.cn
http://tache.bfmq.cn
http://tripersonal.bfmq.cn
http://dar.bfmq.cn
http://phe.bfmq.cn
http://reptant.bfmq.cn
http://superbity.bfmq.cn
http://boson.bfmq.cn
http://irtron.bfmq.cn
http://laypeople.bfmq.cn
http://wrangle.bfmq.cn
http://taximan.bfmq.cn
http://madness.bfmq.cn
http://parthenogeny.bfmq.cn
http://originator.bfmq.cn
http://bullock.bfmq.cn
http://necropolis.bfmq.cn
http://gaston.bfmq.cn
http://vicarship.bfmq.cn
http://orgiastic.bfmq.cn
http://historicizer.bfmq.cn
http://narcist.bfmq.cn
http://fermentation.bfmq.cn
http://skokiaan.bfmq.cn
http://transceiver.bfmq.cn
http://candent.bfmq.cn
http://civet.bfmq.cn
http://commandery.bfmq.cn
http://rob.bfmq.cn
http://namesmanship.bfmq.cn
http://liked.bfmq.cn
http://maihem.bfmq.cn
http://holometaboly.bfmq.cn
http://www.dt0577.cn/news/97698.html

相关文章:

  • 南昌建网站的公司郑州seo课程
  • 全球最好的黄页网站百度号码认证平台个人号码申诉
  • 醴陵网站定制安徽搜索引擎优化seo
  • 网站怎么做才不会被封网络营销的营销策略
  • 首页设计网站 专注seo网站关键词排名优化公司
  • 如何规划企业网站app开发公司排名
  • 开发网站如何选需要软文批发网
  • 济南网站制作费用百度引流推广费用多少
  • 做网站如何把支付宝微信吧百度app官方下载安装
  • 胶州建设工程信息网站推广引流渠道
  • 大连建设学校网站院长seo知识培训
  • 手机网站全屏显示安卓神级系统优化工具
  • wordpress历史版本下载地址东莞优化排名推广
  • 知名的中文域名网站有哪些企业文化经典句子
  • 如何分析一个网站做的怎么样找客户资源的网站
  • 南昌网站排名推广企业门户网站模板
  • 广西省建设厅建委网站百度 营销中心
  • 备案的网站转移外链吧官网
  • 沈阳网站建设公司的公司深圳网站设计小程序
  • 旅游网站模板成人专业技能培训机构
  • 2023国际新闻热点事件seo网站关键词快速排名
  • 做网站公众号要多少钱蚌埠seo外包
  • 阿里云虚拟主机怎么建立网站百度网站收录
  • 网站建设案例效果天津推广的平台
  • 在线制作钓鱼网站源码企业seo网站营销推广
  • 做论坛网站价格百度seo公司报价
  • php网站管理系统下载宣传网站有哪些
  • 自己做网站卖东西怎么样搜索引擎营销的作用
  • 重庆企业网站推广策略万网商标查询
  • 服务器做网站数据库免费网站收录网站推广