标题:数组名作为函数参数的问题
取消只看楼主
一个孩子
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:5
帖 子:356
专家分:954
注 册:2012-10-1
结帖率:96.77%
 问题点数:0 回复次数:2 
数组名作为函数参数的问题
#include<stdio.h>
void Sscores(int scores[10]);
float AVscores(int iscores[10]);
void main()
{
    int scores[10];
    float average;
    Sscores(scores[10]);
    average=AVscores(scores[10]);
    printf("平均成绩是:%d\n",average);

}
void Sscores(int scores[10])
{
    int i;
   
    for(i=0;i<10;i++)
    {
        scanf("%d",&scores[i]);
    }
}
float AVscores(int iscores[10])
{
    float sum=0;
    int i;
    for(i=0;i<10;i++)
    {
        sum=sum+iscores[i];
    }
    return sum;

}
提示的错误是:
1.E:\迅雷下载\我的c语言\数组名作为函数参数.cpp(8) : error C2664: 'Sscores' : cannot convert parameter 1 from 'int' to 'int []'
2.Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
就这两个错误,不知道咋该啊,是不是数据类型有问题呢?还有就是在数组名作为参数时要注意哪些问题啊,求高手指教啊!!!
搜索更多相关主题的帖子: return include average void 
2012-10-01 22:30
一个孩子
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:5
帖 子:356
专家分:954
注 册:2012-10-1
得分:0 
哈哈,高手啊,谢谢啦,但是void Sscores(int scores[10])   ;------------> scores[10] 里面的 10 是必须要写的吧。我自己试了,去掉就编译错误了。

重要的不是结果,是求一个结果的过程,哪怕千难万难,当你有想要的结果时,你已走的很远
2012-10-02 09:59
一个孩子
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:5
帖 子:356
专家分:954
注 册:2012-10-1
得分:0 
本帖不是结分贴 无需结贴。

重要的不是结果,是求一个结果的过程,哪怕千难万难,当你有想要的结果时,你已走的很远
2012-10-03 13:46



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-382428-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.428341 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved