[CareerCup] 12.1 Find Mistakes 找程序错误

简介:

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);

本文转自博客园Grandyang的博客,原文链接:找程序错误[CareerCup] 12.1 Find Mistakes ,如需转载请自行联系原博主。

相关文章
|
2月前
【BUG记录】力扣报错:内存空间不足
【BUG记录】力扣报错:内存空间不足
|
4月前
|
机器学习/深度学习 人工智能 移动开发
一篇文章讲明白hdu4453(splay做法)
一篇文章讲明白hdu4453(splay做法)
21 0
|
5月前
|
Python
Python基础教程——continue语句
Python基础教程——continue语句
|
Python
python中关于IndentationError: expected an indented block 中不易察觉修改原代码错误的解法
python中关于IndentationError: expected an indented block 中不易察觉修改原代码错误的解法
1329 0
python中关于IndentationError: expected an indented block 中不易察觉修改原代码错误的解法
std::map.find()崩溃怪事
std::map.find()崩溃怪事
806 0
Codeforces1486 C2.Guessing the Greatest (hard version)(交互题+奇怪的二分)
Codeforces1486 C2.Guessing the Greatest (hard version)(交互题+奇怪的二分)
46 0