Getting started

The parts of a C program, the types of its values, how arithmetic really behaves, and how to read input and print neat output.

About 9 hours of study

Learning objectives

Lessons

  1. 1

    Your first C program

    The parts every C program has: #include, main, printf and return 0.

  2. 2

    Variables and types

    int, double and char: each variable is a named box of memory with an address and a size.

  3. 3

    Operators and expressions

    Integer division, the remainder %, casts, ++ and +=, and what happens when a number gets too big.

  4. 4

    Input and output: printf and scanf

    Format codes, field widths, and reading numbers with scanf and the & operator.

Module practice

Module quiz

1. What is the value of 5 / 2 * 2.0 in C?
2. Which type best holds a price such as 19.99?
3. Why does scanf("%d", &n) use &?
4. After int x; what is true of x?
5. Which is the right way to print one percent sign with printf?
6. What does (double)7 / 2 give?

Decisions, loops, arrays and strings ›