• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            劉加加在成長(zhǎng)(C++語(yǔ)言學(xué)習(xí)中)

            學(xué)習(xí)、工作、生活,這是三個(gè)問(wèn)題。

              C++博客 :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
              38 隨筆 :: 0 文章 :: 24 評(píng)論 :: 0 Trackbacks

            傳遞數(shù)組參數(shù),其核心就是傳遞該數(shù)組的首地址。然后函數(shù)再通過(guò)數(shù)組、指針等,用該數(shù)組的首地址構(gòu)造一個(gè)新的數(shù)組或指針,再通過(guò)傳遞過(guò)來(lái)的數(shù)組大小,對(duì)該數(shù)組進(jìn)行操作。

            #include <stdio.h>
            #define SIZE 4
            int sumbyarr(int a[],int n);
            int sumbypointer(int *p,int n);
            int sumbyaddress(int address,int n);
            int sumbypointer2(int *begin,int *end)
            int main(void)
            {
                
            int arr[SIZE]={10,20,30,40};
                
            int sum1;
                
            //使用數(shù)組作為形參接收數(shù)組 
                sum1=sumbyarr(arr,SIZE);
                printf(
            "the total of the arr by array is:%d\n",sum1);
                
            //使用指針作為形參接收數(shù)組 
                int sum2;
                sum2
            =sumbypointer(arr,SIZE);
                printf(
            "the total of the arr by pointer is:%d\n",sum2);
                
            //使用地址作為形參接收數(shù)組 
                int sum3;
                sum3
            =sumbyaddress(arr,SIZE);
                printf(
            "the total of the arr by address is:%d\n",sum3);
                   
                //使用兩個(gè)指針形參接收
                int sum4;
                sum4=sumbypointer2(arr,arr+SIZE);
                printf("the total of the arr by pointer2 is:%d\n",sum4);


                getchar();
                
            return 0;

            int sumbyarr(int a[],int n)

                
            int index;
                
            int total=0;
                
            for(index=0;index<n;index++)
                {
                    total
            +=a[index];
                }
                
            return total;
            }
            int sumbypointer(int *p,int n)
            {
                
            int index;
                
            int total=0;
                
            for(index=0;index<n;index++,p++)
                {
                    total
            +=*p;
                }
                
            return total;
            }
            int sumbyaddress(int address,int n)
            {
                
            int *p=address;
                
            int index;
                
            int total=0;
                
            for(index=0;index<n;index++,p++)
                {
                    total
            +=*p;
                }
                
            return total;
            }
            int sumbypointer2(int *begin,int *end)
            {
                int total=0;
                while(begin<end)
                {
                    total+=*begin;
                    begin++;
                }
                return total;
            }

            以上代碼演示怎樣定義有數(shù)組作為參數(shù)的函數(shù)。
            如果數(shù)組作為參數(shù)傳遞進(jìn)入某個(gè)函數(shù),并且在這個(gè)函數(shù)中改變了數(shù)組元素的值,那么程序返回后,這個(gè)數(shù)組元素的值有沒(méi)有改變呢?

            當(dāng)然,值改變了,因?yàn)閿?shù)組是通過(guò)地址傳遞的,改變了被調(diào)函數(shù)中數(shù)組的值也就意味著同時(shí)改變了主調(diào)函數(shù)中數(shù)組的值。因?yàn)樗鼈兊牡刂肥窍嗤摹?
            posted on 2008-05-16 23:54 劉加加 閱讀(1386) 評(píng)論(0)  編輯 收藏 引用 所屬分類(lèi): 學(xué)習(xí)C語(yǔ)言
            国产成人久久AV免费| 久久国语露脸国产精品电影| 色青青草原桃花久久综合| 久久综合九色综合欧美就去吻| 午夜精品久久久内射近拍高清| 国产69精品久久久久APP下载| 狠色狠色狠狠色综合久久 | 亚洲精品无码久久久久AV麻豆| 亚洲乱码中文字幕久久孕妇黑人 | 97久久超碰成人精品网站| 久久精品无码免费不卡| 久久国产欧美日韩精品| 久久久久久免费视频| 久久精品国产精品亚洲毛片 | 狠狠88综合久久久久综合网| 成人亚洲欧美久久久久 | 999久久久国产精品| 久久久噜噜噜久久熟女AA片| 国产成人无码精品久久久久免费 | 国产精品青草久久久久福利99| 日韩久久无码免费毛片软件| 九九精品99久久久香蕉| 久久乐国产综合亚洲精品| 亚洲一本综合久久| 色偷偷偷久久伊人大杳蕉| 久久久久波多野结衣高潮| 91精品国产高清久久久久久91| 亚洲伊人久久精品影院| 国内精品久久国产| 国内精品久久久久久久coent | 少妇人妻综合久久中文字幕| 9191精品国产免费久久| 亚洲国产另类久久久精品小说| 深夜久久AAAAA级毛片免费看| 久久久久国产精品三级网| 亚洲成人精品久久| 香港aa三级久久三级| 久久精品一区二区| 国产精品久久久久久久久免费| 久久综合狠狠综合久久| 亚洲中文字幕无码久久综合网|