当前位置:网站首页>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 !
边栏推荐
- R语言使用ggplot2包的geom_histogram函数可视化直方图(histogram plot)
- TiFlash 面向编译器的自动向量化加速
- 无密码身份验证如何保障用户隐私安全?
- Show strength. In this way, the mobile phone will not be difficult to move forward
- 日化用品行业智能供应链协同系统解决方案:数智化SCM供应链,为企业转型“加速度”
- mysql8.0JSON_CONTAINS的使用说明
- Principle and performance analysis of lepton lossless compression
- 快消品行业SaaS多租户解决方案,构建全产业链数字化营销竞争力
- Tiflash compiler oriented automatic vectorization acceleration
- Matrix chain multiplication dynamic programming example
猜你喜欢

Tiflash compiler oriented automatic vectorization acceleration

Intelligent supply chain collaboration system solution for daily chemical products industry: digital intelligent SCM supply chain, which is the "acceleration" of enterprise transformation

Opengauss database source code analysis series articles -- detailed explanation of dense equivalent query technology (Part 2)

无密码身份验证如何保障用户隐私安全?

Qingda KeYue rushes to the science and Innovation Board: the annual revenue is 200million, and it is proposed to raise 750million

Shenziyu, the new chairman of Meizu: Mr. Huang Zhang, the founder, will serve as the strategic adviser of Meizu's scientific and technological products

SaaS multi tenant solution for FMCG industry to build digital marketing competitiveness of the whole industry chain

CYCA少儿形体礼仪 宁波市培训成果考核圆满落幕

SAS接口有什么优势特点

世界环境日 | 周大福用心服务推动减碳环保
随机推荐
SAS接口有什么优势特点
Geom of R language using ggplot2 package_ Histogram function visual histogram (histogram plot)
Which Internet companies are worth going to in Shenzhen for software testers [Special Edition for software testers]
dynamic programming
The forked VM terminated without saying properly goodbye
TiCDC 6.0原理之Sorter演进
基于 TiDB 场景式技术架构过程 - 理论篇
Section - left closed right open
为什么我认识的机械工程师都抱怨工资低?
Why do mechanical engineers I know complain about low wages?
CyCa children's physical etiquette Ningbo training results assessment came to a successful conclusion
软件测试人在深圳有哪些值得去的互联网公司【软件测试人员专供版】
如何将 DevSecOps 引入企业?
Enjoy what you want. Zhichuang future
【学习笔记】阶段测试1
Kunlun Taike rushes to the scientific innovation board: the annual revenue is 130million, and it plans to raise 500million. CETC Taiji holds 40% of the shares
CYCA少儿形体礼仪 宁波市培训成果考核圆满落幕
PMP考试20天能通过吗?
[learning notes] stage test 1
基于伯努利原理的速度监测芯片可用于天然气管道泄露检测