| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 810 人关注过本帖
标题:初学者向各位高手发问
只看楼主 加入收藏
编程勇者
Rank: 1
等 级:新手上路
帖 子:5
专家分:7
注 册:2010-8-1
结帖率:100%
收藏
已结贴  问题点数:5 回复次数:11 
初学者向各位高手发问
我是初学者,在把谭浩强教程中一个代码输进TC2中时编译成功但结果是错的,不知为什么(是不是软件要调试?),请各位看一下:
#include<stdio.h>
void main()
{
  int max(int x,int y);
  int a,b,c;
  scanf("%d\n,%d",&a,&b);
  c=max(a,b);
  printf("max is%d\n",c);
}
    int max(int x,int y)
    {
    int z;
    if (x>y) z=x;
    else z=y;
    return(z);
    }
我输入1和2结果竟然是3129
搜索更多相关主题的帖子: max return 
2010-08-01 19:07
BlueGuy
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:29
帖 子:4476
专家分:4055
注 册:2009-4-18
收藏
得分:0 
引用:
When people ask why using a void is wrong, (since it seems to work), the answer is usually one of the following:
Because the standard says so.
(To which the answer is usually of the form "but it works for me!")
Because the startup routines that call main could be assuming that the return value will be pushed onto the stack. If main() does not do this, then this could lead to stack corruption in the program's exit sequence, and cause it to crash.
(To which the answer is usually of the form "but it works for me!")
Because you are likely to return a random value to the invokation environment. This is bad, because if someone wants to check whether your program failed, or to call your program from a makefile, then they won't be able to guarantee that a non-zero return code implies failure.
(To which the answer is usually of the form "that's their problem").
This page demonstrates a system on which a void main(void) program will very likely cause problems in the third class above. Calling the program from a script may cause the script to die, whether or not its return code is checked. Calling it from a makefile may cause make to complain. Calling it from the command line may cause an error to be reported.


[ 本帖最后由 BlueGuy 于 2010-8-1 19:17 编辑 ]

我就是真命天子,顺我者生,逆我者死!
2010-08-01 19:14
BlueGuy
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:29
帖 子:4476
专家分:4055
注 册:2009-4-18
收藏
得分:0 
图片附件: 游客没有浏览图片的权限,请 登录注册

图片附件: 游客没有浏览图片的权限,请 登录注册


谭老师确实是分离了, 只是分的有点异样!

[ 本帖最后由 BlueGuy 于 2010-8-1 19:31 编辑 ]

我就是真命天子,顺我者生,逆我者死!
2010-08-01 19:27
BlueGuy
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:29
帖 子:4476
专家分:4055
注 册:2009-4-18
收藏
得分:3 
#include<stdio.h>

int max(int x, int y);

int main(void)
{

    int a, b, c;

    scanf("%d %d", &a, &b);
    c = max(a, b);
    printf("max is%d\n", c);

    return 0;
}

int max(int x,int y)
{
    int z;

    if (x > y)
        z = x;
    else
        z = y;
    return z;
}

我就是真命天子,顺我者生,逆我者死!
2010-08-01 19:37
BlueGuy
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:29
帖 子:4476
专家分:4055
注 册:2009-4-18
收藏
得分:0 
我也是一菜鸟, 只是对 谭浩强 这个词语有点敏感。/

我就是真命天子,顺我者生,逆我者死!
2010-08-01 19:41
caoyuanbccn
Rank: 1
等 级:新手上路
帖 子:7
专家分:7
注 册:2010-8-1
收藏
得分:2 
问题找到了 这段时间听曾怡的课发现一个问题
scanf("%d\n,%d",&a,&b);
曾怡讲如果%d\n,%d 出现在输出语句的格式命令里面时 切不可加入\n,之类的语言包括数字字母等,因为计算机自动会默认a与b之间必须输入\n,才能被计算 否则就是乱码
删除\n, 计算结果正确了

该忘记的总该忘记,我累了,只想要简单的快乐.
2010-08-01 19:49
编程勇者
Rank: 1
等 级:新手上路
帖 子:5
专家分:7
注 册:2010-8-1
收藏
得分:0 
回复 6楼 caoyuanbccn
谢谢不过不是
2010-08-01 20:28
编程勇者
Rank: 1
等 级:新手上路
帖 子:5
专家分:7
注 册:2010-8-1
收藏
得分:0 
回复 5楼 BlueGuy
抱歉...经你们的回答,我发现谭浩强老师是对的,只是输入是要输“,”而已    我何其懵懂
2010-08-01 20:32
forever74
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:CC
等 级:版主
威 望:58
帖 子:1685
专家分:4252
注 册:2007-12-27
收藏
得分:0 
回复 5楼 BlueGuy
超乎一般的敏感就叫做过敏,那就得算是一种病,必须得治啊。

对宇宙最严谨的描述应该就是宇宙其实是不严谨的
2010-08-01 20:37
BlueGuy
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:29
帖 子:4476
专家分:4055
注 册:2009-4-18
收藏
得分:0 
回复 9楼 forever74
是得平静一下,

我就是真命天子,顺我者生,逆我者死!
2010-08-01 20:44
快速回复:初学者向各位高手发问
数据加载中...
 
   



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

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