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

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # C `strcmp()`函數 > 原文: [https://beginnersbook.com/2017/11/c-strcmp-function/](https://beginnersbook.com/2017/11/c-strcmp-function/) **`strcmp()`函數**比較兩個字符串并根據結果返回一個整數值。 ## C `strcmp()`函數聲明 ```c int strcmp(const char *str1, const char *str2) ``` `str1` - 第一個字符串 `str2` - 第二個字符串 ## `strcmp()`的返回值 此函數根據比較結果返回以下值: * 0:如果兩個字符串相等 * `> 0`:如果字符串`str1`的第一個不匹配字符的 ASCII 值**大于**字符串`str2`中的字符 * `< 0`:如果字符串`str1`的第一個不匹配字符的 ASCII 值**小于**字符串`str2`中的字符 > 根據許多在線教程,當第一個字符串大于第二個字符串時,此函數返回正值,這絕對是**不是真的**,或者你可以說沒有正確表達,因為當我們說一個字符串大于第二個字符串時我們在談論長度。但是,此函數不比較長度,它將第一個字符串的每個字符的 ASCII 值與第二個字符串匹配,如果第一個字符串中第一個不匹配字符的 ASCII 值大于第二個字符串的不匹配字符的 ASCII 值,則返回正數。 讓我們舉一個例子來理解這一點。 ## 示例:C 中的`strcmp()`函數 ```c #include <stdio.h> #include <string.h> int main () { char str1[20]; char str2[20]; int result; //Assigning the value to the string str1 strcpy(str1, "hello"); //Assigning the value to the string str2 strcpy(str2, "hEllo"); result = strcmp(str1, str2); if(result > 0) { printf("ASCII value of first unmatched character of str1 is greater than str2"); } else if(result < 0) { printf("ASCII value of first unmatched character of str1 is less than str2"); } else { printf("Both the strings str1 and str2 are equal"); } return 0; } ``` 輸出: ```c ASCII value of first unmatched character of str1 is greater than str2 ``` 在上面的例子中,我們使用函數`strcmp()`比較兩個字符串`str1`和`str2`。在這種情況下,`strcmp()`函數返回一個大于 0 的值,因為第一個不匹配字符`'e'`的 ASCII 值是 101,它大于`'E'`的 ASCII 值 69。 #### 相關文章: 1. [C - `strcat()`示例](https://beginnersbook.com/2017/11/c-strcat-function-with-example/) 2. [C - `strncat()`示例](https://beginnersbook.com/2017/11/c-strncat-function/) 3. [C - `strchr()`示例](https://beginnersbook.com/2017/11/c-strchr-function/)
                  <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>

                              哎呀哎呀视频在线观看