Typedef struct usage

Source: Internet
Author: User

Typedef struct tagmystruct

{
Int inum;
Long llength;
} Mystruct;

The above tagmystruct is the identifier, and mystruct is the variable type (equivalent to (INT, Char, etc )).

 

 

This statement actually completes two operations:

1) define a new structure type

   Struct tagmystruct
{
Int inum;
Long llength;
};

Analysis: tagmystruct is called "tag", that is, "tag". It is actually a temporary name. Whether or not the typedefstruct keyword and tagmystruct constitute this structure type, this structure exists.

We can use struct tagmystruct varname to define variables, but note that it is incorrect to use tagmystruct varname to define variables, Because struct and tagmystruct can be combined to represent a structure type.

2) typedef is named mystruct for the new structure.

Typedef struct tagmystruct mystruct;

Therefore, mystruct is actually equivalent to struct tagmystruct. We can use mystruct varname to define variables.

2.

    Typedef struct tagmystruct
{
Int inum;
Long llength;
} Mystruct;

In C, there are two methods to apply for Structure Variables after this declaration:

(1) variable name of struct tagmystruct

(2) mystruct variable name

In C ++

(1) variable name of struct tagmystruct

(2) mystruct variable name

(3) tagmystruct variable name

Typedef struct usage

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.