<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>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                ### 條件編譯指令 - 條件編譯指令就是有條件地編譯,當滿足某條件時,對一組語句進行編譯,當條件不足時編譯另一組語句。 #### #if指令 **#if指令一般與#else和#elseif指令組合使用格式為:** #if 表達式 程序段 #else 程序段2 #endif 由于條件編譯指令是在預處理階段執行的,因此表達式必須為宏表達式: #include <stdio.h> #define NUM 'c' int main() { #if NUM=='e' printf("The treasure of pirate is buried under your bed.\n"); #else printf("海盜的寶藏就埋在你床下。\n"); #endif return 0; } #### 注意:關于#if……#else……#endif的注意有2點 - #if要對表達式的值進行判斷,因此不能僅定義宏而不給出宏體,要給出宏所代表的值 - 條件編譯#if……#else……#endif與條件語句if……else功能雖然相同,但是兩者時間開銷不同,條件編譯只編譯滿足條件的程序段,可以有效地減少被編譯的語句,從而縮短源代碼的長度,進而達到縮短程序執行時間的目的,條件語句不能減少被編譯的語句,因此無法縮短程序的執行時間 #### #elif指令 #### **#elif和else if相似,只是編譯時不同,對于else if 來說,無論它所檢測的條件是否滿足,該條件對應的語句都會被編譯,但是對于#elif來說,當給定條件不滿足時,該條件對應的語句不會被編譯** #include <stdio.h> #define WORD 'c' int main() { #if WORD=='e' printf("I love you.\n"); #elif WORD=='d' printf("Ich liebe Dich.\n"); #elif WORD=='f' printf("Je t'aime.\n"); #else printf("?ò°????£\n"); #endif//用于結束條件編譯 return 0; } #### #ifdef指令 **該指令檢測的不是宏代表的值,而是宏是否被定義** ~~~ #include <stdio.h> #define MOD int main() { #ifdef MOD//檢測一個宏是否被定義 printf("MOD被定義。\n"); #endif printf("程序結束。\n"); return 0; } ~~~ #### #ifndef的應用 #### **#ifndef可以防止重復定義** 重復定義:如果將一個book.h在一個源文件中包含2次,則book結構類型就被定義了2次。 如果main.c文件中包含了book.h和goods.h,而goods.h中又包含了book.h則main.c中就包含了兩次book.h。為了解決這種由重復而造成的重復定義需要將book.h修改一下 如下所示: book.h內容如下: #ifndef BOOK //假如沒有定義BOOK #define BOOK //定義BOOK struct book //定義book結構類型 { char name[10]; double price; }; #endif//結束條件編譯 goods.h內容如下: #ifndef BOOK //假如沒有定義BOOK #define BOOK //定義BOOK #include "goods.h" struct goods //定義book結構類型 { char name[10]; double price; }; #endif//結束條件編譯 main.c內容如下: #include <stdio.h> #include "book.h" #include "goods.h" int main() { struct book Wild={"教父",42.00}; printf("%-12s%-12s\n","書名","價格"); printf("%-12s%-12.2f\n",Wild.name,Wild.price); 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>

                              哎呀哎呀视频在线观看