当前位置:网站首页>C language elementary (VII) structure
C language elementary (VII) structure
2022-06-21 13:22:00 【Princess Kaka】
One . Structure operation
1. Address fetch
struct Point3D{
int x;
int y;
int z;
};
struct Point3D p = {1,2,3};
printf("&p = %p\n",&p);
printf("&(p.x) = %p\n",&p.x);
printf("&(p.y) = %p\n",&p.y);
printf("&(p.z) = %p\n",&p.z); The structure name is not the address of the structure variable , must Use & Get address .
The array name is the address .
2. The ginseng
void Print(struct Point3D p){
printf("(%d,%d,%d)",p.x,p.y,p.z);
}The entire structure is passed into the function as the value of the parameter . At this time Create a new structure variable in the function and copy the value . Structure can be used as a return value , It is also the overall copy of the structure .
Two . Structure pointer
struct Point3D p = {1,2,3};
struct Point3D* q = &p;1. Structure pointer Visiting members
Structure variables use
.And name access members .
Structure pointers use->And name access members .
struct Point3D p = {1,2,3};
struct Point3D* q = &p;
printf("(%d,%d,%d)",q->x,q->y,q->z); // Equate to printf("(%d,%d,%d)",(*q).x,(*q).y,(*q).z); By modifying the structure pointer q Members pointed to , It also changes the structure variable p Members of the value of the .
2. Structure pointer As a parameter
void Print(struct Point3D* p){
printf("(%d,%d,%d)",p->x,p->y,p->z);// Equate to printf("(%d,%d,%d)",(*q).x,(*q).y,(*q).z);
}3、 ... and . Structure array
struct Point3D ps[] = {
{1,2,3},{1,1,1},{0,0,0}};
for(int i=0;i<3;++i){
printf("(%d,%d,%d)\n",ps[i].x,ps[i].y,ps[i].z);
}Four . Nested structure
struct Line{
struct Point3D start;
struct Point3D end;
};
struct Line line = {
{1,1,1},{0,0,0}};
// Use
printf("(%d,%d,%d)~(%d,%d,%d)",
line.start.x,line.start.y,line.start.z,
line.end.x,line.end.y,line.end.z);
struct Line* p = &line;
printf("(%d,%d,%d)~(%d,%d,%d)",
p->start.x,p->start.y,p->start.z,
p->end.x,p->end.y,p->end.z);Structure contains an array of structures :
struct Triangle{
struct Point3D p[3];
};
struct Triangle t = {
{
{1,2,3},{1,1,1},{0,0,0}}};边栏推荐
- Explanation of common mesh generation methods in workbench
- Eureka's timedsupersortask class (periodic task with automatic interval adjustment)
- Customize view to draw line chart (support zoom)
- [untitled]
- Centos7 deploying MySQL environment
- 基于STM32电压检测和电流检测
- Sharing new experiences in home office | community essay solicitation
- Interpretation of tamigou project: 34% equity transfer of Jining Huayuan Project Management Co., Ltd
- Talk about the delay of public network
- CP Instruction Learning
猜你喜欢
![[in depth understanding of tcapulusdb technology] tcapulusdb construction data](/img/83/200cd9705138583eee6b3db55135ff.png)
[in depth understanding of tcapulusdb technology] tcapulusdb construction data

Apache ShardingSphere 5.1.2 发布|全新驱动 API + 云原生部署,打造高性能数据网关

Distributed transaction processing scheme big PK

Work content of service governance

Flink CDC MongoDB Connector 的实现原理和使用实践

【深入理解TcaplusDB技术】TcaplusDB构造数据
JS 中的集合引用类型

基于STM32电压检测和电流检测
![[untitled]](/img/3c/c34a8cbbe398cecd54050b30f95b66.png)
[untitled]

Memcached (high performance memory object cache)
随机推荐
SCCM creates a client collection based on the installed app and periodically pushes application updates
Eureka's timedsupersortask class (periodic task with automatic interval adjustment)
小程序直播互动功能运行在App里?
Highly available configuration of database (MySQL)
Sharing new experiences in home office | community essay solicitation
PHP uses grafika to synthesize pictures and generate poster images
Kubernetes快速實戰與核心原理剖析
Summary of the latest remote deployment O & M tools
Qinglong panel, JD timed task library, script library
Kubernets Rapid Practical fighting and Core Principle Analysis
Are you still using generator to generate crud code of XXX management system? Let's see what I wrote
使用seaborn绘制热图
[deeply understand tcapulusdb technology] tmonitor background one click installation
Kube-prometheus grafana安装插件和grafana-image-renderer
How to read AI summit papers?
高效远程办公手册| 社区征文
seaborn绘图风格的设置
处理接口幂等性的两种常见方案
hands-on-data-analysis 第二单元 第四节数据可视化
Reading notes on how to connect the Internet ADSL