<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國際加速解決方案。 廣告
                # C 程序:使用按引用調用以循環順序交換數字 > 原文: [https://www.programiz.com/c-programming/examples/swapping-cyclic-order](https://www.programiz.com/c-programming/examples/swapping-cyclic-order) #### 在此示例中,使用按引用調用以循環順序交換用戶輸入的三個數字。 要理解此示例,您應該了解以下 [C 編程](/c-programming "C tutorial")主題: * [C 指針](/c-programming/c-pointers) * [C 按引用進行調用:使用指針](/c-programming/c-pointer-functions) * * * ## 按引用調用交換元素的程序 ```c #include <stdio.h> void cyclicSwap(int *a, int *b, int *c); int main() { int a, b, c; printf("Enter a, b and c respectively: "); scanf("%d %d %d", &a, &b, &c); printf("Value before swapping:\n"); printf("a = %d \nb = %d \nc = %d\n", a, b, c); cyclicSwap(&a, &b, &c); printf("Value after swapping:\n"); printf("a = %d \nb = %d \nc = %d", a, b, c); return 0; } void cyclicSwap(int *n1, int *n2, int *n3) { int temp; // swapping in cyclic order temp = *n2; *n2 = *n1; *n1 = *n3; *n3 = temp; } ``` **輸出** ```c Enter a, b and c respectively: 1 2 3 Value before swapping: a = 1 b = 2 c = 3 Value after swapping: a = 3 b = 1 c = 2 ``` 在此,用戶輸入的三個數字分別存儲在變量`a`,`b`和`c`中。 這些數字的地址將傳遞到`cyclicSwap()`函數。 ```c cyclicSwap(&a, &b, &c); ``` 在`cyclicSwap()`的函數定義中,我們已將這些地址分配給了指針。 ```c cyclicSwap(int *n1, int *n2, int *n3) { ... } ``` 當`cyclicSwap()`內部的`n1`,`n2`和`n3`改變時,`a`,`b`和`main()`內部的`c`也被更改。 **注意**: `cyclicSwap()`函數未返回任何內容。
                  <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>

                              哎呀哎呀视频在线观看