当前位置:网站首页>Structure - C language
Structure - C language
2022-07-05 14:21:00 【Cwxh0125】
Why use a structure
If the data you want to express is complex , It's not a value For example, you want to express the date There are three values of month, year and day , If you want to express so many data gathered together as a whole Then we need to use Structure
A structure is a composite data type
#include <stdio.h>
int main(int argc,char const *argv[])
{
struct date {
int month;
int day;
int year;
};
struct date toaay;
today. month = 07;
today.day = 31;
today .year = 2014;
printf( "Today's date is %i-%i-%i.\n",
today.year,today.month,today.day ) ;
return 0;
}
Within the function / Outside ?
And local variables — sample , The structure type declared inside the function can only be used inside the function
Therefore, the structure type is usually declared outside the function ,
In this way, it can be used by multiple functions
The form of the declaration structure
Three methods
struct point {
int x;
int y;};struct point pl, p2;pl and p2 All are point There are x and y Value
struct {
int x;
int y;} p1,p2 ;p1 and p2 It's all a nameless structure , There are x and y
struct point {
int x;
int y;} pl, p2;pl and p2 All are point There are x and y Value
Initialization of structure
#include <stdio.h>
struct date {
int month;
int day;
int year;
};
int main(int argc, char const *argv[])
{
struct date today = {07,31,2014}; \\ Assign values by
struct date thismonth = {.month=7, .year=2014}; \\ Assign assignment
printf("Today's date is %i-%i-%i.\n",
today. year,today.month,today.day ) ;
printf("This month is %i-%i-%i. ln",
thismonth.year,thismonth.month,thismonth.day ) ;
return 0;
}
Structural members
Structure and array are a bit like
Arrays use operators and subscripts to access their members a[0] =10;
For structure . Operators and names access their members
today.day visit today The structure of the day
p1.x visit p1 The structure of the x
Structural operations
To access the whole structure , Directly use the name of the structure variable for the whole structure , It can be assigned 、 Address fetch , It can also be passed to function parameters
pl = (struct point){5,I0}; amount to pl.x= 5; pl.y = l0;
pl =p2; amount to pl.x = p2.x; pl.y = p2.y;
Arrays can't do these two operations !
边栏推荐
- Oneconnect listed in Hong Kong: with a market value of HK $6.3 billion, ye Wangchun said that he was honest and trustworthy, and long-term success
- Guofu hydrogen energy rushes to the scientific and Technological Innovation Board: it plans to raise 2billion yuan, and 360million yuan of accounts receivable exceed the revenue
- How to introduce devsecops into enterprises?
- Which Internet companies are worth going to in Shenzhen for software testers [Special Edition for software testers]
- Thymeleaf 常用函數
- 申请代码签名证书时如何选择合适的证书品牌?
- The IPO of Ruineng industry was terminated: the annual revenue was 447million and it was planned to raise 376million
- Qingda KeYue rushes to the science and Innovation Board: the annual revenue is 200million, and it is proposed to raise 750million
- 无密码身份验证如何保障用户隐私安全?
- Total amount analysis accounting method and potential method - allocation analysis
猜你喜欢

TiFlash 源码解读(四) | TiFlash DDL 模块设计及实现分析

Tidb DM alarm DM_ sync_ process_ exists_ with_ Error troubleshooting

Thymeleaf 模板的创建与使用

日化用品行业智能供应链协同系统解决方案:数智化SCM供应链,为企业转型“加速度”

How to introduce devsecops into enterprises?

openGauss数据库源码解析系列文章—— 密态等值查询技术详解(下)

How can non-technical departments participate in Devops?

Shen Ziyu, nouveau Président de Meizu: M. Huang Zhang, fondateur de Meizu, agira comme conseiller stratégique pour les produits scientifiques et technologiques de Meizu

软件测试人在深圳有哪些值得去的互联网公司【软件测试人员专供版】

ASP. Net large takeout ordering system source code (PC version + mobile version + merchant version)
随机推荐
如何深入理解“有限状态机”的设计思想?
How to protect user privacy without password authentication?
Make the seckill Carnival more leisurely: the database behind the promotion (Part 2)
Why do mechanical engineers I know complain about low wages?
汇编语言 assembly language
R語言ggplot2可視化:可視化折線圖、使用theme函數中的legend.position參數自定義圖例的比特置
Assembly language
周大福践行「百周年承诺」,真诚服务推动绿色环保
Show strength. In this way, the mobile phone will not be difficult to move forward
TDengine 社区问题双周精选 | 第三期
Google eventbus usage details
判断变量是否为数组
R语言dplyr包select函数、group_by函数、mutate函数、cumsum函数计算dataframe分组数据中指定数值变量的累加值、并生成累加数据列
03_ Dataimport of Solr
Mingfeng medical sprint technology innovation board: annual revenue of 350million yuan, proposed to raise 624million yuan
最长公共子序列 - 动态规划
What is the future development trend of neural network Internet of things
VC开发非MFC程序内存泄漏跟踪代码
What are the advantages and characteristics of SAS interface
freesurfer运行完recon-all怎么快速查看有没有报错?——核心命令tail重定向