Skip to content
Justice Tech School

Variables and Types

Declare a variable with a type before use. Common types are int, float, double and char. Initialise variables because locals start with garbage.

Example
#include <stdio.h>

int main(void) {
  int age = 30;
  double pi = 3.14159;
  char grade = 'A';
  printf("%d %.2f %c\n", age, pi, grade);
  return 0;
}

Result

30 3.14 A

Exercise

Declare an integer.

 n = 5;

Quiz Test

What does an uninitialised local hold?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.