In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "how to define and use C language structure array". The content of the explanation in this article is simple and clear, and it is easy to learn and understand. let's study and learn "how to define and use C language structure array".
Introduction
A structural variable can store a set of information about a student, but what if there are 10 students? Do you want to define 10 structural variables? Does the above program have to be copied and pasted 10 times?
It is obviously impossible to use an array at this point. There is also an array in the structure, called the structure array. It is almost identical to the numerical array mentioned earlier, except that each element of the structure array is a variable of the structure type and contains all the member items in the structure.
The method of defining a structure array is simple, the same as defining a structure variable, except that the variable is changed into an array. Or the definition of a normal array is exactly the same as that described earlier, such as:
Struct STUDENT stu [10]
This defines a structure array with 10 elements, each of which is a structure variable and contains all structure members.
A reference to a structure array is the same in principle as a reference to a structure variable. It's just that there are multiple structure variables in the structure array, so we just need to use the elements in the structure array one by one using the for loop.
The following is to write a program that requires: enter the basic information of 5 students from the keyboard, such as name, age, gender, student number, and then output the basic information of the student with the largest student number to the screen.
# include # include struct STU {char name [20]; int age; char sex; char num [20];}; void OutputSTU (struct STU stu [5]); / / function declaration. The function is to output the student information int main (void) {int i; struct STU stu [5]; for (iTun0; I) with the largest student number.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.