Skip to content
AgileLogics
5 min read

Variables & Data Types

Prerequisites: How C code runs

Every C variable has a fixed type with a specific, predictable size in memory.

Syntax

int age = 36;
double price = 19.99;
char grade = 'A';

Example

int score = 10;
printf("%d\n", score);
score = 20;
printf("%d\n", score);

Expected output

10
20

Unlike int, double, and char, there is no built-in String type — a piece of text is a char array, covered in its own lesson shortly. Use const for a value that shouldn't change:

const int MAX_SCORE = 100;

Common mistakes

  • Using %d in printf for a double (or vice versa) — the format specifier must match the actual type, since C has no way to check this for you at compile time; a mismatch produces garbage output.
  • Using an uninitialized variable — unlike some languages, C does not automatically zero out a local variable; it starts as whatever garbage bits were already in that memory.

Practice

Declare a const char called grade holding 'A', then print it with %c.

Show solution
const char grade = 'A';
printf("%c\n", grade);