当前位置:网站首页>C language learning log 1.24

C language learning log 1.24

2022-06-13 04:58:00 Today is also a day without baldness

typedef:

        C language ⾔ Provides ⼀ One is called typedef To declare ⼀ Of existing data types New name .

                ⽐ Such as : typedef int Length; bring Length Become int Alias for type .

        • such , Length This name can replace int It's in the place of variable definition and parameter declaration :

                                Length a, b, len ;

                                Length numbers[10] ;

Declare the name of the new type —— The new name is some kind of alias , He improved the readability of the program

typedef int Length; // Length It is equivalent to int type 
 typedef char* Strings[10]; // Strings  yes 10 An array of strings 
 The type of 
 typedef struct node {
int data;
struct node *next; 
 } aNode;
 or 
typedef struct node aNode; //  such ⽤aNode  It can replace 
struct node

union : 

        C Consortia in language , It is a structure of multiple variables that uses a memory area at the same time , The value of the region is the value of the variable with the largest length in the structure . Its usage and structure are similar

union AnElt { 
 int i; 
 char c; 
} elt1, elt2; // Defined elt1,elt2 Two about structure Anelt The consortium of 
elt1.i = 4; // Yes elt1 Medium i assignment 
elt2.c = ’a’; // Yes elt2 Medium c assignment 
elt2.i = 0xDEADBEEF;// Yes elt2 Medium i assignment , this elt2 The memory footprint in is i Occupy 

  TIPS: About Union , It has only one member at a time , All members share the same memory area ,union The size of is the size of its largest member .

TIP: The processing method of the small end is that the low end is in front . 

原网站

版权声明
本文为[Today is also a day without baldness]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202280517425735.html