免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
楼主: zeus82
打印 上一主题 下一主题

有关于x++的一个问题 [复制链接]

论坛徽章:
0
11 [报告]
发表于 2008-07-24 09:56 |只看该作者
对于这种题,俺已经不敏感了.

论坛徽章:
0
12 [报告]
发表于 2008-07-24 09:57 |只看该作者

回复 #11 xi2008wang 的帖子

呵呵,偶尔看看蛮有意思的

论坛徽章:
1
双子座
日期:2015-01-04 14:25:06
13 [报告]
发表于 2008-07-24 10:03 |只看该作者
第一个gcc的警告
warning: operation on `x' may be undefined

论坛徽章:
1
双子座
日期:2015-01-04 14:25:06
14 [报告]
发表于 2008-07-24 10:04 |只看该作者
第二个也一样的警告
warning: operation on `x' may be undefined

论坛徽章:
0
15 [报告]
发表于 2008-07-24 10:05 |只看该作者
原帖由 yecheng_110 于 2008-7-24 10:04 发表
第二个也一样的警告
warning: operation on `x' may be undefined



什么代码?

论坛徽章:
1
双子座
日期:2015-01-04 14:25:06
16 [报告]
发表于 2008-07-24 10:06 |只看该作者
就LZ的代码呀

论坛徽章:
0
17 [报告]
发表于 2008-07-24 10:08 |只看该作者

回复 #16 yecheng_110 的帖子

没有直接cpy他的代码gcc……
你什么编译器

论坛徽章:
0
18 [报告]
发表于 2008-07-24 10:10 |只看该作者
原帖由 net_robber 于 2008-7-24 09:44 发表
楼主有实际测试过么???


$ cat test.c
#include
int main(void)
{
        int x=5;
        x=x++;
        printf("%d\n",x);
}
$ gcc test.c
$ ./a.out
6

#include<stdlib.h>
#include<stdio.h>
#include<time.h>
#include<error.h>
#include<string.h>

int main()
{
        int x = 5;
        x = x++;
        printf("%d\n", x);
        return 0;
}


[root@localhost home]# g++ -o newtest newtest.cpp
[root@localhost home]# ./newtest
5
我的结果是这样的

论坛徽章:
0
19 [报告]
发表于 2008-07-24 10:16 |只看该作者
原帖由 zeus82 于 2008-7-24 10:10 发表

#include
#include
#include
#include
#include

int main()
{
        int x = 5;
        x = x++;
        printf("%d\n", x);
        return 0;
}


[root@localhost home]# g++ -o newt ...


匪夷所思,呵呵

论坛徽章:
0
20 [报告]
发表于 2008-07-24 10:17 |只看该作者
原帖由 aple_smx 于 2008-7-24 09:50 发表
> CC -o test test.cc
> ./test
7
> cat test.cc
#include
int main(void)
{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int x=5;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x=x+++2;
...

[root@localhost home]# cat newtest.cpp
#include<stdio.h>

int main()
{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int x = 5;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x = x+++2;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf("%d\n", x);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return 0;
}


[root@localhost home]# g++ -o newtest newtest.cpp
[root@localhost home]# ./newtest
8
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP