当前位置:网站首页>Initial structure
Initial structure
2022-06-23 01:43:00 【'Dream_】
If you will It's better to start than to give up . Roman.
May we all have our own goals and are making unremitting efforts for them .
-----------------------------------------------------------------------
One 、 Declaration of a structure
One ) Basic knowledge of structure
A structure is a collection of values , These values are called member variables . Each member of a structure can be a variable of a different type .
Two ) Declaration of a structure
Form like :
struct tag // struct( keyword )+ Structural tag
{
member-list; // Member variables
}variable-list; // Variable list
example :
// Structure
struct Stu
{
char name[20]; // name
int age; // Age
char sex[8]; // Gender
float score; // achievement
}s1,s2,s3;
// s1,s2,s3 It's through struct Stu Variable created by type
// s1,s2,s3 Global variable// typedef Type redefinition / Type renaming
typedef struct Stu Stu;
// You can use Stu Instead of struct Stuint main()
{
// struct Stu Is the structure type , You can't omit struct
struct Stu s4;
struct Stu s5;
// s4,s5 It's a local variable
Stu s6;
// typedef Can be used after Stureturn 0;
}
// typedef Another waystruct Stu
{
char name[20]; // name
int age; // Age
char sex[8]; // Gender
float score; // achievement
}Stu; // At this time, you can only write the name of the heavy life here , Cannot write variable list
3、 ... and ) Type of structure member
Structure members can be Scalar 、 Array 、 The pointer , Even structures .
Four ) Structure variable definition and initialization
1. Structure initialization Curly braces { }
2. Pointer to the variable Address or Vent pointer NULL
------------------------------------------------------------------------------
Two 、 Access to structure members
1. Structure member access operator :
- Structural variable . Structure member name
- Structure pointer -> Structure member name
2. example :
// Structure access
struct Stu
{
char name[20];
int age;
};
void print(struct Stu* ps) {
printf("name = %s age = %d\n", (*ps).name, (*ps).age);
// Use structure pointers to access members that point to objects
printf("name = %s age = %d\n", ps->name, ps->age);
}
int main()
{
struct Stu s = { "zhangsan", 20 };
print(&s);// Structure address transfer parameter
return 0;
}
// If the structure has multiple layers According to The pointer -> or Variable . Just visit 3. modify Member contents of structure variables
- Members are ordinary : =( assignment )
- Members are arrays : strcpy( ,); // The header file string.h
------------------------------------------------------------------------------
3、 ... and 、 Structural parameters
One ) Pass on Structural variable
Pass on Structural variable , namely Value passed : An argument is a temporary copy of a formal parameter .
- It will waste a lot of space
- When changing the contents of formal parameters through functions , Arguments don't change , High security
Two ) Pass on Structure pointer
Pass on Structure pointer , namely Address transmission .
- Account for only a 4/8 byte , Less space
- To improve security , When transferring parameters Add... Before the formal parameter const modification
3、 ... and ) Summary
When a function passes parameters , Parameters need to be stacked .
If you pass a structure object , The structure is too large , The system overhead of parameter stack pressing is large , So it will lead to performance degradation
- Each function call will open up a space in the stack area of memory
- Memory ( From top to bottom ):
The stack area : local variable 、 Function parameter
Heap area : Dynamic memory development Such as :malloc 、free 、calloc 、realloc
Static zone : Static variables 、 Global variables
- Summary : Structural parameters , To transmit Structure address
------------------------ All a person's anger comes from the pain of his incompetence .------------------------
边栏推荐
- leetcode 91. Decode ways (medium)
- Vector 6 (inheritance)
- Wechat mobile terminal development - account login authorization
- 关于打算做一个web的问题看板,需要使用哪些方面语言及数据库知识!
- Debian10 installing zabbix5.4
- Extend your kubernetes API using the aggregation API
- Unit of RMB in words
- Knowledge point learning
- Random decoding NLP
- HDU - 7072 double ended queue + opposite top
猜你喜欢

Installing MySQL for Linux

ERROR { err: YAMLException: end of the stream or a document separator is expected at line 6, colum

LeetCode 206. 反转链表(迭代+递归)

Template specialization template <>

7.new, delete, OOP, this pointer

Express framework installation and start service

LeetCode 206. Reverse linked list (iteration + recursion)

Steps to implement a container global component

Byte order: big endian vs little endian

office2016+visio2016
随机推荐
Nuxt - auto generate dynamic route bug
Development status of full color LED display
HDU - 7072 double ended queue + opposite top
[template] KMP
Do you know the memory components of MySQL InnoDB?
OOP multiple storage (class template)
The road of architects starts from "storage selection"
The devil cold rice # 099 the devil said to travel to the West; The nature of the boss; Answer the midlife crisis again; Specialty selection
使用aggregation API扩展你的kubernetes API
A hundred lines of code to realize reliable delay queue based on redis
Analysis of current mainstream video coding technology | community essay solicitation
fatal: refusing to merge unrelated histories
Pat class A - 1015 reversible primes
Detailed explanation of clip attribute parameters
Use of higher order functions
C language student achievement ranking system
Unique in Pimpl_ PTR compilation errors and Solutions
Autumn move script C
Philosopher's walk gym divide and conquer + fractal
7.new, delete, OOP, this pointer