• <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ǔ)言
            国产精品99久久不卡| 99久久99久久精品国产片果冻 | 热久久这里只有精品| 久久精品国产亚洲欧美| 国产亚洲美女精品久久久| 久久综合亚洲色HEZYO国产| 午夜精品久久久久久久久| 狠狠色丁香久久婷婷综| 久久综合视频网站| 欧美久久综合性欧美| 一级a性色生活片久久无| 久久国产精品一国产精品金尊| 国内精品久久久久久中文字幕| 欧美黑人激情性久久| 久久这里只有精品首页| 一本久道久久综合狠狠爱| 久久久久久久久久久免费精品| 少妇人妻88久久中文字幕| 久久伊人中文无码| 久久r热这里有精品视频| 午夜不卡久久精品无码免费| 久久综合伊人77777麻豆| 国产综合免费精品久久久| 99久久99这里只有免费费精品| 99久久综合国产精品免费| 久久久久国产精品麻豆AR影院| 久久精品国产69国产精品亚洲| 亚洲αv久久久噜噜噜噜噜| 2021国内久久精品| 久久亚洲精品国产亚洲老地址 | 久久综合五月丁香久久激情| 777久久精品一区二区三区无码| 日韩AV无码久久一区二区| 久久无码人妻一区二区三区| 亚洲午夜久久久久久久久久| 综合人妻久久一区二区精品| 青青草原综合久久大伊人| 国产毛片欧美毛片久久久| 亚洲精品无码久久久久久| 久久99精品久久久久子伦| .精品久久久麻豆国产精品|