ctci/11. Testing/11.1. Mistake.md

343 B

11.1. Mistake

Find the mistake(s) in the following code

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

One mistake is syntax in the for, it lacks {}. The printf is taking a digit but i is unsigned int.

Unsigned int is always greater than or qual to zero, it will remain in 0 and the loop will run infinitely.