Lesson 5 / 38

Variables

Declare typed variables, initialise them, use const and #define, and print values with printf format specifiers.

Declare with a type

You must state the type. Uninitialised variables hold garbage.

int   age   = 25;
float price = 9.99f;
char  grade = 'A';
int   score;        // unknown until assigned
score = 100;

Constants

const double PI = 3.14159; cannot be reassigned. #define MAX 50 is a compile-time text swap.

Printing them

printf uses format specifiers: %d int, %f float, %c char, %s string. printf("n = %d\n", n);