当前位置:网站首页>Section 7 - structures

Section 7 - structures

2022-06-13 04:47:00 Stretch the curtain with the wind

Catalog

1. Declaration of a structure

1.1 Basic knowledge of structure

1.2 Statement of structure

1.3 Type of structure member

1.4 Structure variable definition and initialization

2. Access to structure members

3. Structural parameters

3.1. Value transfer call

3.2. Address call

3.3. summary


1. Declaration of a structure

1.1 Basic knowledge of structure

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

and

Array Is a collection of the same elements

The objects in life are complex

Structure is used to describe complex objects

1.2 Statement of structure

struct tag
{
        member-list;
variable-list;

There are two ways to create structure variables :

The first way to create it :

  The second way to create :

The difference between the two structure variables :

The structure variables created by the first creation method are local

The structure variables created by the second creation method are global

1.3 Type of structure member

The members of a structure can be scalars 、 Array 、 The pointer , Even other structures .

1.4 Structure variable definition and initialization


2. Access to structure members


3. Structural parameters

3.1. Value transfer call

  notes : Structural variables are generally large , If you make a value passing call in the structure , A formal parameter is a temporary copy of an argument , In this case, the waste of space is serious

3.2. Address call

  notes : The formal parameter pointer variable of the address transfer call stores the address of the actual parameter , It only needs 4/8 Bytes

3.3. summary

  notes :

1. Any function call will apply for space in the stack area

2. The stack area will give main Function allocates a space , Access some... In this space main Local variables in functions . When a function is called , First, transfer parameters , Will be main A copy of the arguments in the function , The memory space of the copy is allocated in main Above the space occupied by the function , Then allocate a part of the memory space above the formal parameter variable to the function .

3. Similar to the stack in the data structure : Insert elements at the top of the stack , Delete elements at the top of the stack . Inserting elements at the top of the stack is called pressing the stack , Deleting elements at the top of the stack is called out of the stack . When a function passes parameters, it is similar to function stack pressing .

 

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 relatively large , So it can lead to performance degradation .
therefore : When structures transmit parameters , To transfer the address of the structure .

原网站

版权声明
本文为[Stretch the curtain with the wind]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202280520088638.html