typedef struct a{}; and typedef struct A{}A; what's the difference?

Source: Internet
Author: User

Problem Source: http://www.cskaoyan.com/viewthread.php?tid=244542&pid=1593533&page=1&extra= #pid1593533

My answer:

First of all, on the structure of the supplement, the domestic classic textbook-Tan Haoqiang's "C + + programming" clearly stated:
1, in C language, the definition of the structure of the variable format: struct A;
2, in C + +, the definition of the structure of the variable format: a A;
In addition, C + + retained the style, that is, C + + can be struct a A, also can use a, Mr. Tan suggested a new way of writing A;

So the question can be answered as follows:
(1) in C language (or C-style program):
Using the typedef struct A{}A You can define a struct variable without having to write struct A, which is written directly into a (a is the typedef struct A{}A after a), in order to omit struct to make the program more concise;
The use of the typedef struct a{} to define the structure variables must be written struct a A, can not omit struct;

(2) in the C + + language (or C + +-style programs):
In C + + generally will not appear typedef struct A{}A Such superfluous form, the reason may be divided between C and C + +;

In addition, the structure of C and C + + is also a little different: C structure can not contain functions, C + + structure may contain functions, but generally do not do so instead of using the method of the class implementation.

Note: The king of the single book "Data Structure" is the use of C language.

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.