设为首页收藏本站

新微赢技术网

 找回密码
 注册
搜索
热搜: 回贴
查看: 608|回复: 0
打印 上一主题 下一主题

不明白

[复制链接]
跳转到指定楼层
1#
发表于 2009-11-4 00:14:34 | 只看该作者 回帖奖励 |正序浏览 |阅读模式
//arrfun2.cpp -- function with an array argument
#include<iostream>
const int ArSize=8;
int sum_arr(int arr[],int n);

//use std:: instead of using directive
int main()
{
    int cookies[ArSize]={1,2,4,8,16,32,64,128};
// some systems require preceding int with static to
// enable array initialization
   
    std::cout<<cookies<<" = array addres, ";
// some systems require a type cast: unsigned(cookies)

    std::cout<<sizeof cookies<<" = sizeof cookies\n";
    int sum=sum_arr(cookies,ArSize);
    std::cout<<"Total cookies eaten: "<<sum<<std::endl;
    sum=sum_arr(cookies,3);
    std::cout<<"First three eaters ate "<<sum<<" cookies.\n";
    sum=sum_arr(cookies+4,4);
    std::cout<<"Last four eaters ate "<<sum<<" cookies.\n";
   
    system("pause");
    return 0;
}

//return the sum of an integer array
int sum_arr(int arr[],int n)
{
    int total=0;
    std::cout<<arr<<" = arr, ";
// some systems requires a type cast: unsigned(arr)
   
    std::cout<<sizeof arr<<" = sizeof arr\n";
    for(int i=0;i<n;i++)
       total=total+arr[i];
您需要登录后才可以回帖 登录 | 注册

本版积分规则

申请友链|小黑屋|最新主题|手机版|新微赢技术网 ( 苏ICP备08020429号 )  

GMT+8, 2024-11-18 20:46 , Processed in 0.155873 second(s), 9 queries , Gzip On, Memcache On.

Powered by xuexi

© 2001-2013 HaiAn.Com.Cn Inc. 寰耽

快速回复 返回顶部 返回列表