Programmer --- C language details 21 (# difference between define and typedef, structure details)

Source: Internet
Author: User

Programmer --- C language details 21 (# difference between define and typedef, structure details)
Main Content: # difference between define and typedef, struct details

# Include

 
  
# Define INT_D int * # define CHAR_D char int main () {/* # difference between define and typedef */typedef int * INT_T; typedef char CHAR_T; INT_T a, B; // both a and B are int-type pointers INT_D c and d; // c is int-type pointers and d is int-type Integer unsigned CHAR_D e; /// the define type definition can be extended. // unsigned CHAR_T f; // This sentence is incorrect, type Def redefinition type cannot be added with Type Extension/* structure details * // Test 1 struct foo {int foo;} foo; // The final foo is a variable declared by the structure foo // foo test; // it is incorrect to define a structure directly like this foo. foo = 1; // The struct name can be the same as the internal variable name printf ("foo = % d \ n", foo. foo); // Test 2 typedef struct fun {int fun;} fun; fun fn; // can be defined at this time/* Conclusion: 1. Do not use typedef for struct for convenience, the only advantage is that you do not need to write struct, but this keyword can prompt you with some information, which should not be omitted. 2. typedef is used in arrays, structures, pointers, and function combination types; portable type. When you need a type of at least 20 bits, you can perform the typedef operation. In this way, when the code is transplanted to an inaccessible platform, you need to select the correct types such as short, int, and long, you only need to modify typedef, instead of modifying each type */return 0 ;}

 

Output:


Related Article

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.