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
- Write, compile and read a small program
- Choose the right type for a value
- Predict integer division and casts
- Use printf and scanf correctly
Lessons
- 1
Your first C program
The parts every C program has: #include, main, printf and return 0.
- 2
Variables and types
int, double and char: each variable is a named box of memory with an address and a size.
- 3
Operators and expressions
Integer division, the remainder %, casts, ++ and +=, and what happens when a number gets too big.
- 4
Input and output: printf and scanf
Format codes, field widths, and reading numbers with scanf and the & operator.
Module practice
- C: Greet by nameEasy
- C: A sum and a productMedium
- C: Printing special charactersHard
- C: Next yearEasy
- C: Characters are numbersMedium
- C: An area and its whole partHard
- C: Average of twoEasy
- C: Hours, minutes and secondsMedium
- C: A product too big for an intHard
- C: Add two numbersEasy
- C: A receipt lineMedium
- C: Reading mixed inputHard