Sample Video Frame

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

Exercise 10: Switch Statements

In other languages like Ruby, you have a switch-statement that can take any expression. Some languages like Python don't have a switch-statement because an if-statement with Boolean expressions is about the same thing. For these languages, switch-statements are more like alternatives to if-statements and work the same internally.

In C, the switch-statement is actually quite different and is really a jump table. Instead of random Boolean expressions, you can only put expressions that result in integers. These integers are used to calculate jumps from the top of the switch to the part that matches that value. Here's some code to help you understand this concept of jump tables:

View Source file ex10.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.