iT邦幫忙

DAY 29
8

C++ 指標 30日系列 第 25

C++ 指標 30日(29)

衝啊!pointer!


今日主題:函數的傳址呼叫(續)

昨天的範例也可以用另一種方式(用指標取代陣列名稱)來寫。

請看程式碼:

#include <stdio.h>

int findMax(int *, int);
main()
{
    int arr[] = {10, 20, 50, 9, 1, 7, 9999, 0, 87};
    int count;
    
    count = sizeof(arr)/sizeof(arr[0]);
    printf("%d\n",findMax(arr, count));   
}

int findMax(int *x, int cnt){
    int i;
    int result = *x;
    
    for (i = 0; i < cnt; i++){
        if (*(x+i) > result){
            result = *(x+i);
        }
    }
    return result;
}

結果同樣為:9999

鐵人文總整理


上一篇
C++ 指標 30日(28)
下一篇
C++ 指標 30日(30)
系列文
C++ 指標 30日26
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

2 則留言

0
總裁
iT邦好手 1 級 ‧ 2013-10-14 11:29:38

明天就功德圓滿了...讚

ted99tw iT邦高手 1 級 ‧ 2013-10-14 11:34:28 檢舉

焚我殘軀,熊熊烈火。生亦何歡,死亦何苦?灑花

總裁 iT邦好手 1 級 ‧ 2013-10-14 11:35:29 檢舉

生日快樂

0
一級屠豬士
iT邦大師 1 級 ‧ 2013-10-14 11:38:50

明年會在繼續嗎?
疑惑

看更多先前的回應...收起先前的回應...
總裁 iT邦好手 1 級 ‧ 2013-10-14 11:46:44 檢舉

明年可能會一次報8組...汗

ted99tw iT邦高手 1 級 ‧ 2013-10-14 11:49:18 檢舉

我4組總裁4組...偷笑

有沒有AV組?
會不會出現貼圖組?
或是歪樓大賽呢?

ted99tw iT邦高手 1 級 ‧ 2013-10-14 11:50:38 檢舉

不是說好明年要波記憶體那鍋..開心

ted99tw iT邦高手 1 級 ‧ 2013-10-14 11:51:55 檢舉

hitomitanaka提到:
會不會出現貼圖組?

今年我文的圖就佔了約一半..臉紅

記憶體...那海綿寶寶呢

ted99tw iT邦高手 1 級 ‧ 2013-10-14 12:17:58 檢舉

不要管他,他一定是忘了~

我要留言

立即登入留言