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

Lessons

  1. 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. 2

    Loops: for, while and do-while

    Repeat code with a counter, until a condition fails, or at least once; break and continue.

  3. 3

    Arrays

    Many values of one type side by side in memory, indexes from 0, and what happens past the end.

  4. 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

Module quiz

1. What does if (x = 0) do?
2. What is the problem with for (i = 0; i <= n; i++) on an array of n elements?
3. How much room does the string "Dhaka" need in a char array?
4. What does strcmp(a, b) return when the strings are equal?
5. Why can a[10] on int a[10] be so dangerous in C?
6. Which loop checks its condition only after the body has run?

‹ Getting startedFunctions and pointers ›