Three definitions of c language struct

Source: Internet
Author: User

Struct type variable definition

Struct type variables have the same definitions as other types of variables. However, the struct type needs to be defined in advance, so the definition form of struct type variables increases flexibility, there are three forms, which are described as follows:

1) first define the struct type, and then define the struct type variable:
Struct stu/* define the student struct type */
{
Char name [20];/* Student name */
Char sex;/* Gender */
Long num;/* student ID */
Float score [3];/* score of the three subjects */
};
Struct stu student1, student2;/* defines the struct type variable */
Struct stu student3, student4;
With this struct type, you can define more variables of this struct type.

2) define the struct type and define the struct type variables at the same time:
Struct data
{
Int day;
Int month;
Int year;
} Time1, time2;
You can also define the following variables:
Struct data time3, time4;
With this struct type, you can also define more variables of this struct type.

3) directly define struct type variables:
Struct
{
Char name [20];/* Student name */
Char sex;/* Gender */
Long num;/* student ID */
Float score [3];/* score of the three subjects */
} Person1, person2;/* defines the struct type variable */
This definition method cannot record the struct type. Therefore, except for direct definition, this struct type variable cannot be defined. I have been using C for the first time for five years.

Related Article

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.