Use of typedef

Source: Internet
Author: User

Typedef can be used to define your own data types, but I always forget to use the format, which is easy to confuse with # define. Today I suddenly think of how to write typedef is not easy to write wrong.

For example, if I want to define a double type variable real, it is written as double real; this beginner C language will; at this time, I only need to add a typedef before this statement to change it to typedef double real; real is defined as a new type instead of a variable. The new custom type is actually double.

 

Another example is:

Double real [20];

-->

Typedef double real [20];

Real is defined as a new type, which is an array type with 20 double data types. You can use the following:

Real height, longth;

Then, height longth is an array of the double type with 20 elements.

Double height [20], longth [20];

The effect is the same, but it looks more concise.

 

Double * doublepointer; doublepointer is a pointer to the double type.

-->

Typedef double * doublepointer;

The doublepointer is defined as a new type. It is easy to define a pointer to the double type:

Doublepointer dptr;

 

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.