C Language Basics Tutorial (iv) Pointers, structures, unions, and enumerations (11)

Source: Internet
Author: User
3. Structure array and structure pointers
Structs are a new type of data, and can also have structure arrays and structure pointers.
An array of structures
An array of structures is a collection of variables with the same struct type. If you want to define the name, sex, age, and address of 40 students in a class, you can define an array of structures. As shown below:
struct{
Char Name[8];
Char sex[2];
int age;
Char addr[40];
}STUDENT[40];
can also be defined as:
struct string{
Char Name[8];
Char sex[2];
int age;
Char addr[40];
};
struct string student[40];
It is necessary to point out that the access of a struct array member is a structural variable of an array element in the form of:
Structure array element. Member name
For example:
Student[0].name
Student[30].age
In fact, the structure array is equivalent to a two-dimensional construct, the first dimension is a structure array element, each element is a structural variable, and the second dimension is a struct member.
Attention:
A member of a struct array can also be an array variable.
For example:
struct A
{
int m[3][5];
float F;
Char s[20];
}Y[4];
In order to access this variable of struct variable y[2] in structure A, it can be written as
Y[2].M[1][4]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.