Decisions, loops, arrays and strings
How programs choose and repeat, and how many values of one kind are stored side by side, including text.
About 13 hours of study
Learning objectives
- Choose between paths with conditions and switch
- Write loops that start and stop correctly
- Use arrays within their bounds
- Handle strings and their terminator
Lessons
- 1
Decisions: if, else and switch
Run code only when a condition is true, chain choices with else if, and pick one case with switch.
- 2
Loops: for, while and do-while
Repeat code with a counter, until a condition fails, or at least once; break and continue.
- 3
Arrays
Many values of one type side by side in memory, indexes from 0, and what happens past the end.
- 4
Strings are char arrays
The '\0' at the end, string.h functions, reading words and lines, and buffers that are too small.
Module practice
- C: Even or oddEasy
- C: Letter gradeEasy
- C: Days in a monthMedium
- C: Income taxHard
- C: Sum from 1 to nEasy
- C: Times tableEasy
- C: Reverse the digitsMedium
- C: A diamond of starsHard
- C: Largest and smallestEasy
- C: Print in reverseEasy
- C: Second largestMedium
- C: Merge two sorted arraysHard
- C: Count vowelsEasy
- C: Palindrome wordMedium
- C: Reverse each wordHard