Back to Blog

C in 100 Seconds: Variables and Types | Episode 2

Daryl WongDaryl Wong

Video: C in 100 Seconds: Variables — int float char double | Episode 2 by Taught by Celeste AI - AI Coding Coach

Watch full page →

Variables and Types — Storing Data in C

C in 100 Seconds, Episode 2


C is a statically typed language. Every variable has a type, and you declare it up front. No guessing, no auto-detection.

The Four Core Types

int age = 25;
float price = 9.99;
char grade = 'A';
double pi = 3.14159265;
  • int — whole numbers. 4 bytes on most systems.
  • float — decimal numbers. ~7 digits of precision.
  • char — a single character, wrapped in single quotes.
  • double — double-precision floating point. ~15 digits of precision.

Printing Variables

Each type has its own format specifier for printf:

printf("Age: %d\n", age);         // %d for int
printf("Price: %.2f\n", price);   // %.2f for float (2 decimals)
printf("Grade: %c\n", grade);     // %c for char
printf("Pi: %.8f\n", pi);         // %.8f for double (8 decimals)

Get the specifier wrong and you get garbage output. C trusts you to match them correctly.

Why Types Matter

C doesn't have a universal "number" type. The type determines how much memory is allocated and how the bits are interpreted. An int and a float storing "the same number" look completely different in memory.

Full Code

#include <stdio.h>

int main() {
  int age = 25;
  float price = 9.99;
  char grade = 'A';
  double pi = 3.14159265;

  printf("Age: %d\n", age);
  printf("Price: %.2f\n", price);
  printf("Grade: %c\n", grade);
  printf("Pi: %.8f\n", pi);

  return 0;
}

Compile and Run

gcc variables.c -o variables
./variables

Next episode: Format Specifiers — controlling exactly how your data is displayed.

Student code: github.com/GoCelesteAI/c-in-100-seconds/episode02