Typedef and typedef struct and # define

Source: Internet
Author: User

# Define n 100000

With this definition, using N in a program represents 100000.

Typedef int word4

Give the int A new name word4.

 

(Transfer)StructDifferences from typedef struct

It can be divided into three parts:
1 first: // Note that C and C ++ are different.
To define a struct type in C, use typedef:
Typedef struct student
{
Int;
} Stu;
So when declaring the variable, you can: Stu stu1; (if there is no typedef, you must use struct student stu1; to declare it)
The Stu here is actually the alias of struct student. Stu = struct student
In addition, student can also be left empty here (so it cannot be struct student stu1; it must be Stu stu1 ;)
Typedef struct
{
Int;
} Stu;
However, in C ++
Struct student
{
Int;
};
As a result, student of the struct type is defined, and student stu2 is directly used when the variable is declared;
========================================================== ===

2. Second:
In C ++, if typedef is used, the following differences may occur:
Struct student 

Int; 
} Stu1 ;// Stu1 is a variable

 
Typedef struct student2 

Int; 
} Stu2;// Stu2 is a struct type = struct student

 
You can directly access stu1.a during use.
But stu2 must first stu2 S2;
Then s2.a = 10;
========================================================== =

Typedef and typedef struct and # define

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.