当前位置:网站首页>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 !
边栏推荐
- What is the future development trend of neural network Internet of things
- Which Internet companies are worth going to in Shenzhen for software testers [Special Edition for software testers]
- Shenziyu, the new chairman of Meizu: Mr. Huang Zhang, the founder, will serve as the strategic adviser of Meizu's scientific and technological products
- 日化用品行业智能供应链协同系统解决方案:数智化SCM供应链,为企业转型“加速度”
- CyCa children's physical etiquette Ningbo training results assessment came to a successful conclusion
- 无密码身份验证如何保障用户隐私安全?
- The speed monitoring chip based on Bernoulli principle can be used for natural gas pipeline leakage detection
- Thymeleaf th:classappend attribute append th:styleappend style append th:data- custom attribute
- R語言ggplot2可視化:可視化折線圖、使用theme函數中的legend.position參數自定義圖例的比特置
- How to protect user privacy without password authentication?
猜你喜欢

周大福践行「百周年承诺」,真诚服务推动绿色环保

What category does the Internet of things application technology major belong to

TiCDC 6.0原理之Sorter演进

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

申请代码签名证书时如何选择合适的证书品牌?

Chow Tai Fook fulfills the "centenary commitment" and sincerely serves to promote green environmental protection

ASP. Net large takeout ordering system source code (PC version + mobile version + merchant version)

ASP.NET大型外卖订餐系统源码 (PC版+手机版+商户版)
![Which Internet companies are worth going to in Shenzhen for software testers [Special Edition for software testers]](/img/c2/a5f5fe17a6bd1f6f9df828ddd224d6.png)
Which Internet companies are worth going to in Shenzhen for software testers [Special Edition for software testers]

Current situation, trend and view of neural network Internet of things in the future
随机推荐
Total amount analysis accounting method and potential method - allocation analysis
C - Divisors of the Divisors of An Integer Gym - 102040C
Don't be unconvinced. Mobile phone function upgrade is strong
直播预告|如何借助自动化工具落地DevOps(文末福利)
Share 20 strange JS expressions and see how many correct answers you can get
非技术部门,如何参与 DevOps?
The IPO of Ruineng industry was terminated: the annual revenue was 447million and it was planned to raise 376million
Thymeleaf th:with局部变量的使用
The forked VM terminated without saying properly goodbye
Scenario based technology architecture process based on tidb - Theory
别不服气。手机功能升级就是强
如何深入理解“有限状态机”的设计思想?
Section - left closed right open
做自媒體視頻二次剪輯,怎樣剪輯不算侵權
申请代码签名证书时如何选择合适的证书品牌?
Intelligent supply chain collaboration system solution for daily chemical products industry: digital intelligent SCM supply chain, which is the "acceleration" of enterprise transformation
Thymeleaf 模板的创建与使用
R语言ggplot2可视化条形图:通过双色渐变配色颜色主题可视化条形图、为每个条形添加标签文本(geom_text函数)
R语言使用MASS包的polr函数构建有序多分类logistic回归模型、使用coef函数获取模型中每个变量(自变量改变一个单位)对应的对数优势比(log odds ratio)
Make the seckill Carnival more leisurely: the database behind the promotion (Part 2)