<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++ 程序:使用引用調用以循環順序交換數字 > 原文: [https://www.programiz.com/cpp-programming/examples/swapping-cyclic-order](https://www.programiz.com/cpp-programming/examples/swapping-cyclic-order) #### 該程序從用戶那里獲取三個整數,并使用指針以循環順序交換它們。 要理解此示例,您應該了解以下 [C++ 編程](/cpp-programming "C++ tutorial")主題: * [C++ 指針](/cpp-programming/pointers) * [通過引用進行 C++ 調用:使用指針(帶有示例)](/cpp-programming/pointers-function) * * * 用戶輸入的三個變量分別存儲在變量`a`,`b`和`c`中。 然后,將這些變量傳遞給函數`cyclicSwap()`。 而不傳遞實際變量,而是傳遞這些變量的地址。 當這些變量在`cyclicSwap()`函數中以循環順序交換時,在`main`函數中的變量`a`,`b`和`c`也將自動交換。 ## 示例:使用按引用調用交換元素的程序 ```cpp #include<iostream> using namespace std; void cyclicSwap(int *a, int *b, int *c); int main() { int a, b, c; cout << "Enter value of a, b and c respectively: "; cin >> a >> b >> c; cout << "Value before swapping: " << endl; cout << "a, b and c respectively are: " << a << ", " << b << ", " << c << endl; cyclicSwap(&a, &b, &c); cout << "Value after swapping numbers in cycle: " << endl; cout << "a, b and c respectively are: " << a << ", " << b << ", " << c << endl; return 0; } void cyclicSwap(int *a, int *b, int *c) { int temp; temp = *b; *b = *a; *a = *c; *c = temp; } ``` **輸出** ```cpp Enter value of a, b and c respectively: 1 2 3 Value before swapping: a=1 b=2 c=3 Value after swapping numbers in cycle: a=3 b=1 c=2 ``` 注意,我們沒有從`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>

                              哎呀哎呀视频在线观看