Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

C language structure body array how to define

2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

Today, the editor will share with you the relevant knowledge points about how to define the c language structure array. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article, let's take a look at it.

Structure array

An array whose element type is a struct type is called a struct array. The structure body array itself has all the characteristics of the array. When used according to the operation mode of the array, each element of it is a structure volume variable, and enter according to the operation mode of the structure volume variable.

Do all kinds of operations.

Definition of structure array

The general form of the structure array definition:

Struct structure type name array name [array length]

When defining an array of structures using the above form, the structure type must be defined. For example:

Struct student

{

Int id

Char name [20]

Char gender

Double score

}

Struct student stu [30]; ∥ defines an array of structures with length 30

You can also define an array of structures while defining the structure type, for example:

Struct student

{

Int id

Char name [20]

Char gender

Double score

} stu [30]

The use of structure array

The use of the structure array is similar to the use of the basic variable array, usually the use of array elements, because each array element is a structure variable, the use of the array element is the same as the structure variable.

A general form that refers to a member of an array element of a structure:

Structure array name [subscript]. Member name

For example, the element stub [I] of the previously defined structure array stu can do the following:

Stub [I] .id = 101

Scanf ("% s", stu [I]. Name)

Scanf ("% d", & stub [I]. Score)

Putchar (stu [I]. Gender)

Variables defined using the same structure type can be assigned to each other. Then values can also be assigned to each other between elements of an array of structures of the same type, and between elements of an array and variables of the same type. For example, after the following drawing defines the structure variable and the structure array, you can assign values accordingly.

Struct student shud

Struct student stu [10]

Stud=stu [2]

Stu [3] = stu [1]

These are all the contents of the article "how to define the c language structure array". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report