Sample Video Frame

Created by Zed A. Shaw Updated 2026-08-31 20:32:57
 

Exercise 8: If, Else-If, Else

In C, there really isn't a Boolean type. Instead, any integer that's 0 is false or otherwise it's true. In the last exercise, the expression argc > 1 actually resulted in 1 or 0, not an explicit True or False like in Python. This is another example of C being closer to how a computer works, because to a computer, truth values are just integers.

However, C does have a typical if-statement that uses this numeric idea of true and false to do branching. It's fairly similar to what you would do in Python and Ruby, as you can see in this exercise:

View Source file ex8.c Only

Previous Lesson Next Lesson

Register for Learn C the Hard Way

Register today for the course and get the all currently available videos and lessons, plus all future modules for no extra charge.