C语言基础入门详解三

chatgpt/2023/9/27 17:25:28

前些天发现了一个蛮有意思的人工智能学习网站,8个字形容一下"通俗易懂,风趣幽默",感觉非常有意思,忍不住分享一下给大家。
👉点击跳转到教程

一、C语言之函数指针

#include<stdio.h>
#include<stdlib.h>
/**函数指针 
*/ 
//定义一个函数 
int add(int x,int y){return x+y; 
} 
main(){//定义函数指针int (*android)(int x, int y);//函数指针赋值android = add;//使用函数指针int result = android(12,15);printf("result==%d\n",result);system("pause");
} 

输出到控制台内容如下:

在这里插入图片描述
二、C语言中联合体的理解

#include<stdio.h>
#include<stdlib.h>
/**Unition联合体 
*/ 
//定义一个联合体,特点,所有的字段都是使用同一块内存空间 
union Mix{long i;//4个字节int k; //4个字节char ii; //1个字节 
};
main(){printf("mix:%d\n",sizeof(union Mix));//实验union Mix m;m.i = 100;m.k = 123;m.ii = 50; printf("m.i==%d\n",m.i); printf("m.k==%d\n",m.k);printf("m.k==%d\n",m.ii);system("pause");
} 

输出到控制台内容如下:

在这里插入图片描述
三、C语言中的枚举

#include<stdio.h>
#include<stdlib.h>
/**枚举的值是递增的 默认首元素的值是0 
*/ 
enum WeekDay{Monday=0,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday 
};
main(){enum WeekDay day = Wednesday;printf("%d\n",day); system("pause");
} 

输出到控制台内容如下:

在这里插入图片描述
四、C语言中的结构体

#include<stdio.h>
#include<stdlib.h>/**结构体 
*/ 
//定义结构体 
struct student{int age;float score;char sex;
};
main(){//使用结构体 struct student stu = {18,95.6,'W'};//结构体取值 printf("stu.age==%d\n",stu.age);printf("stu.score==%.1f\n",stu.score);printf("stu.sex==%c\n",stu.sex);//结构体赋值stu.age = 20;stu.score = 100;stu.sex = 'M'; printf("stu.age==%d\n",stu.age);printf("stu.score==%.1f\n",stu.score);printf("stu.sex==%c\n",stu.sex);//结构体的长度printf("struct student 结构体的长度==%d\n",sizeof(struct student)); system("pause");
} 

输出到控制台内容如下:

在这里插入图片描述
五、C语言中结构体指针

#include<stdio.h>
#include<stdlib.h>/**结构体指针 
*/ 
//定义结构体 
struct student{int age;float score;char sex;
};
main(){//使用结构体 struct student stu = {18,95.6,'W'};//结构体指针struct student* point = &stu;struct student** point2 = &point;//取值运算  (*point).age 等价于 point->age printf("(*point).age ==%d\n",(*point).age);printf("point->age ==%d\n",point->age );printf("point->score ==%f\n",point->score );printf("point->sex ==%c\n",point->sex );//赋值运算point->age = 20; point->score = 100; point->sex = 'M'; printf("point->age ==%d\n",point->age);printf("point->score ==%f\n",point->score);printf("point->sex ==%c\n",point->sex );//二级结构体指针取值  (*point).age 等价于 point->age 所以 (**point).age 等价于 (*point)->ageprintf("(**point2).age ==%d\n",(**point2).age);printf("(*point2)->age ==%d\n",(*point2)->age );printf("(*point2)->score ==%f\n",(*point2)->score );printf("(*point2)->sex ==%c\n",(*point2)->sex ); //二级结构体指针赋值运算(*point2)->age = 60;printf("(*point2)->age ==%d\n",(*point2)->age); system("pause");
} 

输出到控制台内容如下:

在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.exyb.cn/news/show-5314852.html

如若内容造成侵权/违法违规/事实不符,请联系郑州代理记账网进行投诉反馈,一经查实,立即删除!

相关文章

【visual studio2019】如何打开即时窗口

在 Visual Studio2019 中打开即时窗口&#xff0c;有两种方法&#xff1a; 1、可以通过“调试”菜单&#xff0c;然后选择“窗口”下的“即时窗口”选项 2、直接使用快捷键“Ctrl Alt I” 此时即时窗口将显示在 Visual Studio2019 的底部。在即时窗口中&#xff0c;可以执…

华为OD真题--选修课--带答案

2023华为OD统一考试&#xff08;AB卷&#xff09;题库清单-带答案&#xff08;持续更新&#xff09;or2023年华为OD真题机考题库大全-带答案&#xff08;持续更新&#xff09; 项目描述 现有两门选修课&#xff0c;每门选修课都有一部分学生选修&#xff0c;每个学生都有选修课…

js中css压缩方法

最近一直在做邮件html发送。其中邮件排版中&#xff0c;很多邮箱对css大小有要求&#xff0c;必需要有压缩css的办法&#xff0c;以前的做法是去各大在线压缩工具中压缩好后&#xff0c;再加入邮件html中。随着邮件html模板越做越多后&#xff0c;这个压缩就很繁琐&#xff0c;…

ESP32cam系列教程003:ESP32cam实现远程 HTTP_OTA 自动升级

文章目录 1.什么是 OTA2. ESP32cam HTTP_OTA 本地准备2.1 HTTP OTA 升级原理2.2 开发板本地基准程序&#xff08;程序版本&#xff1a;1_0_0&#xff09;2.3 开发板升级程序&#xff08;程序版本&#xff1a;1_0_1&#xff09;2.4 本地 HTTP_OTA 升级测试2.4.1 本地运行一个 HT…

基本不等式@平均值不等式@双勾函数不等式

文章目录 基本不等式基本齐次不等式一次形式&#x1f47a;基本不等式拓展拓展1拓展2 算数平均数和几何平均数不等式应用恒等变形 双勾函数不等式导数函数单调性&#x1f388;求解过程 极值点和极值函数单调性的简单证明&#x1f388; 基本不等式 基本齐次不等式 设 a , b ∈ …

Rule110

Rule 110 is a one-dimensional cellular automaton with interesting properties (such as being Turing-complete). There is a one-dimensional array of cells (on or off). At each time step, the state of each cell changes. In Rule 110, the next state of each ce

webstorm配置less转译

Program中路径如果识别不到 项目文件\node_modules.bin\lessc

图片识别文字在线转换,这几个方法很好用

随着科技的不断发展&#xff0c;图片文字在线转换已经成为了一个非常方便的工具。通过这个工具&#xff0c;我们可以将图片中的文字转换成电子文本&#xff0c;方便我们进行编辑、存储和分享。本文将介绍一些好用的方法和注意事项&#xff0c;帮助大家更好地使用图片文字在线转…
推荐文章