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

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                # 在 C++ 中將數組傳遞給函數 > 原文: [https://beginnersbook.com/2017/08/cpp-passing-array-to-function/](https://beginnersbook.com/2017/08/cpp-passing-array-to-function/) 您可以將[數組](https://beginnersbook.com/2017/08/cpp-arrays/)作為參數傳遞給函數,就像將變量作為參數傳遞一樣。為了將數組傳遞給函數,您只需要**在函數調用**中提及數組名稱,如下所示: ```cpp function_name(array_name); ``` ## 示例:將數組傳遞給函數 在這個例子中,我們傳遞兩個數組`a`和`b`到函數`sum()`。此函數相加兩個數組的相應元素并顯示它們。 ```cpp #include <iostream> using namespace std; /* This function adds the corresponding ?* elements of both the arrays and ?* displays it. ?*/ void sum(int arr1[], int arr2[]){ int temp[5]; for(int i=0; i<5; i++){ temp[i] = arr1[i]+arr2[i]; cout<<temp[i]<<endl; } } int main(){ int a[5] = {10, 20, 30, 40 ,50}; int b[5] = {1, 2, 3, 4, 5}; //Passing arrays to function sum(a, b); return 0; } ``` **輸出:** ```cpp 11 22 33 44 55 ``` ## 示例 2:將多維數組傳遞給函數 在這個例子中,我們將[多維數組](https://beginnersbook.com/2017/08/cpp-multidimensional-arrays/)傳遞給函數`square`,該函數顯示每個元素的平方。 ```cpp #include <iostream> #include <cmath> using namespace std; /* This method prints the square of each ?* of the elements of multidimensional array ?*/ void square(int arr[2][3]){ int temp; for(int i=0; i<2; i++){ for(int j=0; j<3; j++){ temp = arr[i][j]; cout<<pow(temp, 2)<<endl; } } } int main(){ int arr[2][3] = { ? ? ? ?{1, 2, 3}, ? ? ? {4, 5, 6} }; square(arr); return 0; } ``` **輸出:** ```cpp 1 4 9 16 25 36 ```
                  <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>

                              哎呀哎呀视频在线观看