about struct and typedef structs

Source: Internet
Author: User

To

1 struct   telphone{23            char name[]; 4 5            Char  teinumber[]; 6 };

As an example, we first define a telphone structure.

Join needs to define an alias for Telphone:

Its syntax is

typedef  Telphone  TP;

And actually telphone as a struct,

It's better to write like this

Tepedef struck Telphone TP;

Because our telphone is our custom type, so we understand, but others do not necessarily understand, if we add struck this keyword, others will know that this is a custom type, and will not be confusing.

So it eventually evolved into

The following wording

struct telphone{             char    name[];              Char    telnumber[];} TP;

At this point, we can define

OK

struct Telphone TP1;

can also, directly

TP TP2;

If we don't need struct telphone, we can also directly

struct {             char    name[];              Char    telnumber[];} TP;

This allows the structure to be defined only by TP.

The difference in C + +

If we define the

1 struct   telphone{2            char name[]; 3           Char  teinumber[]; 4  };

Then you can directly view the same telphone to define the structure variables.

Telphone TP1;

In C + +

    struct       Student   {       int   A;   }STU1; // STU1 is a variable  

STU1 represents a struct variable of type student

and

typedef   struct   Student2   {       int   A;   } STU2; // STU2 is a struct type =struct Student  

There is no difference in the C language.

about struct and typedef structs

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.