Skip to content
FollowtheDamnCode

Data Types

int, float, and char — whole numbers, decimals, and letters.

3 minute read

Big idea

The type says what kind of value a variable can hold.

The idea

Three types you'll use all the time:

TypeHoldsExamplePrint with
intwhole numbersint count = 7;%d
floatdecimalsfloat price = 9.5;%f
charone characterchar grade = 'A';%c

Example

Try it — edit it and run it again
#include <stdio.h>

int main(void) {
    int count = 7;
    float price = 9.5;
    char grade = 'A';

    printf("%d\n", count);
    printf("%.2f\n", price);
    printf("%c\n", grade);
    return 0;
}
output
7
9.50
A

Run and edit it in the app.

%.2f means "show 2 digits after the decimal point".

Watch it

Think of it like

Different containers for different things: a coin box for whole coins, a measuring cup for amounts like 9.5, and a name tag with room for just one letter.

🕷️ Spidey-sense: You wouldn't carry web fluid in a paper bag. A type is the right container for the job: int for whole numbers, float for decimals, char for a single letter. Pick the container first, then put things in.

Common mistake

A char uses single quotes. Double quotes are for text (strings).

char grade = "A";   // ✗
char grade = 'A';   // ✓

Key terms

  • int — A whole number, like 7 or -3.
  • float — A number with a decimal point, like 9.5.
  • char — A single character, like 'A'.

Check yourself

Which type stores a decimal number like 3.14?

Which is the right way to store the letter A?

Which format code prints an int?