<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                #### 結構體 ```c struct student { const char *name; const char *address; int age; }; ``` struct student表示一個類型,類似于int,聲明和初始化,以及使用如下: ```c #include <stdio.h> #include <string.h> struct student { const char *name; const char *address; int age; }; int main(int argc, char const *argv[]) { struct student person = {"wuzhc", "Guangzhou", 18}; printf("%s\n", person.name); return 0; } ``` #### typeof別名 可以為結構體設置別名,如下 ```c typedef struct student { const char *name; const char *address; int age; } stu; ``` 其中結構體名可以省略,如下: ```c typedef struct { const char *name; const char *address; int age; } stu; ``` #### 結構體復制 當一個結構體變量賦值給另一個結構體變量時,計算機會創建一個全新的副本,如果結構體含有指針,那么復制的僅僅是指針的值,如下: #### 嵌套結構 ```c #include <stdio.h> #include <string.h> typedef struct { const char *subject; int score; } report; typedef struct { const char *name; const char *address; int age; report card; // 這是一個嵌套結構體 } stu; int main(int argc, char const *argv[]) { stu person = {"wuzhc", "Guangzhou", 18, {"english", 59}}; printf("%s\n", person.card.subject); return 0; } ``` #### 結構體指針 類似于其他類型指針,代碼如下: ```c void modifyAge(stu *s) { s->age = 23; // 等價于(*s).age = 23 } ``` #### 聯合union 當定義聯合時,計算機會為最大的字段分配空間,如php的zend_value如下: ```c typedef union _zend_value { zend_long lval; //int整形 double dval; //浮點型 zend_refcounted *counted; zend_string *str; //string字符串 zend_array *arr; //array數組 zend_object *obj; //object對象 zend_resource *res; //resource資源類型 zend_reference *ref; //引用類型,通過&$var_name定義的 zend_ast_ref *ast; //下面幾個都是內核使用的value zval *zv; void *ptr; zend_class_entry *ce; zend_function *func; struct { uint32_t w1; uint32_t w2; } ww; } zend_value; ``` 初始化: ```c zend_value zv = {.dval=1.5} ``` #### 枚舉 關鍵字enum,定義如下: ```c typeof enum { COUNT, POUNDS, PINTS } unit; ``` #### 位字段 用位字段主要用于減少占用空間,如定義一個結構如下: ```c typedef struct { unsigned int fist_visit:1; unsigned int come_age:1; unsigned int fingers_lost:4; unsigned int days_a_week:3; } survey; ``` 位字段應當聲明為unsigned int;只有出現在同一個結構中,位字段才能節省空間 #### 位字段和數值計算 最大值 = 2^位數 - 1,即4位只能保存0到15的值 #### demo ```c #include <stdio.h> #include <string.h> // 枚舉 typedef enum { PREPATE_TYPE, HOMEWORK_TYPE, SCANEXAM_TYPE } sourceType; // 聯合 typedef union { short count; short weight; } quantity; // 結構體 typedef struct { const char *subject; int score; } report; // 結構體 typedef struct { const char *name; const char *address; int age; report card; // 這是一個嵌套結構體 sourceType type; quantity q; } stu; // 位字段 typedef struct { unsigned int fist_visit:1; unsigned int come_age:1; unsigned int fingers_lost:4; unsigned int days_a_week:3; } survey; // 結構體指針 void modifyAge(stu *s) { s->age = 23; // 等價于(*s).age = 23 } int main(int argc, char const *argv[]) { stu person = {"wuzhc", "Guangzhou", 18, {"english", 59}, HOMEWORK_TYPE, {.weight=118}}; if (person.type == HOMEWORK_TYPE) { printf("%s\n", "homework"); } else { printf("%s\n", "other"); } modifyAge(&person); printf("%i\n", person.age); printf("%i\n", person.q); return 0; } ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看