码迷,mamicode.com
首页 > 其他好文 > 详细

[CareerCup] 12.1 Find Mistakes 找程序错误

时间:2015-10-23 07:52:46      阅读:165      评论:0      收藏:0      [点我收藏+]

标签:

 

12.1 Find the mistake(s) in the following code:

unsigned int i;
for (i = 190; i >= 0; --i)
printf("%d\n", i);

 

这道题让我们找出给定的简短的程序的错误,这里共有两处错误:

1. 无符号整型永远大于0,所以i >= 0没有意义

2. 打印无符号整型要用%u

正确代码参见下方:

 

unsigned int i;
for (i = 190; i > 0; --i)
printf("%u\n", i);

 

[CareerCup] 12.1 Find Mistakes 找程序错误

标签:

原文地址:http://www.cnblogs.com/grandyang/p/4903350.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!