标题:[求助]C中返回值问题
取消只看楼主
妍清舞
Rank: 1
等 级:新手上路
帖 子:121
专家分:0
注 册:2007-11-12
 问题点数:0 回复次数:0 
[求助]C中返回值问题
#include<stdio.h>
char str[80];
int nl=0,nw=0,nn=0,no=0;
int main()
{
void add (char str[]);/*对add函数的声明*/
printf("请输入一串字符串:\n");
gets (str);/*向字符数组str输入一个字符串*/
add (str);/*对add函数的调用*/
printf("letter=%d space=%d number=%d others=%d\n",nl,nw,nn,no);
return 0;
}
void add (char str[])/*定义add函数*/
{
int i;
for(i=0;str[i] != '\0';i++)
{
if ((str[i] >= 'a' && str[i] <= 'z')||(str[i] >= 'A' && str[i] <= 'Z'))
++nl;
else if (str[i] == ' ')
++nw;
else if (str[i] >= '0' && str[i] <= '9')
++nn;
else
++no;
}
return ;
}


以上是我编的一个小程序,有些不明白的地方:我定义的函数类型为void,无返回值,为什么执行printf("letter=%d space=%d number=%d others=%d\n",nl,nw,nn,no);时仍有正确结果,请问什么情况下可以不需要返回值,但主函数用到时依然能正确输出,什么情况下必须有返回值?
搜索更多相关主题的帖子: 返回值 
2007-11-12 22:40



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




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

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