Topic 11 of 100 Data Types and Variables Interactive Tutorial

Understanding C Data Types: Categories, Sizes, and Examples

13 mins read Last updated: 22 Aug 2026 25,100 views
C Compiler 0.00%

What is Understanding C Data Types? Core Concept & Direct Summary

Core Objective & Problem Statement

What are the basic, derived, enumerated, and void data types in C, and how many bytes do they occupy?

Direct Answer Summary

Imagine moving to a new apartment. You wouldn't rent a warehouse for a backpack, and you can't fit a sofa into a shoebox. Space matters — and choosing the right amount matters.

C thinks about data the same way. Before you storeanythingin a C program, you must tell the compiler exactly what kind of data it is and how much memory to reserve. That declaration is called adata type— and it's one of the first decisions in every line of C you'll ever write.

This might feel fussy if you're coming from Python, where variables figure out their own types. But C's approach is deliberate:explicit types make programs faster, smaller, and more predictable.And understanding them gives you something precious — a mental model of how computers actually store information.

In this guide, you'll learn every C data type category, exact sizes and ranges, and how to choose the right one — with runnable examples throughout.

How Does Understanding C Data Types Work? In-Depth Mechanics & Architecture

What Is a Data Type in C?

Adata typeis a classification that tells the compiler three things about a piece of data:

  1. How much memoryto reserve (in bytes)
  2. What kind of valuesare allowed (whole numbers? decimals? characters?)
  3. What operationsare legal (you can divide numbers, but not characters... well, mostly)
main.c
Run Online
int age = 25;
// "reserve 4 bytes for a whole number called age"

C isstatically typed— the type is locked in at compile time and can never change while the program runs. That strictness catches whole categories of bugs before your program even starts.

The Three Categories of C Data Types

C organizes its types into three families:

CategoryWhat It ContainsExamples
Primary (Basic)Built-in fundamental typesint,char,float,double,void
DerivedTypes builtfromprimary typesarrays, pointers, functions
User-DefinedTypesyouinventstruct,union,enum,typedef

This article masters theprimarytypes — the foundation everything else stands on. (Derived and user-defined types get their own dedicated guides, linked at the end.)

Primary Data Type #1: int — The Workhorse

intstoreswhole numbers— no decimal points, no fractions.

main.c
Run Online
int students = 32;
int temperature = -7;
int year = 2026;

Memory size:typically4 bytes(32 bits) on modern systemsRange:roughly−2.1 billion to +2.1 billion

The int Family: Size Modifiers

C lets you resize integers with modifiers:

TypeTypical SizeRange (approximate)
short int2 bytes−32,768 to 32,767
int4 bytes±2.1 billion
long int4 or 8 bytessystem-dependent
long long int8 bytes±9.2quintillion

And each comes in anunsignedflavor — trade away negatives, double your positive range:

main.c
Run Online
unsigned int population = 4000000000U;
// up to ~4.2 billionunsigned char brightness = 255;
// 0 to 255 — perfect for pixel values!

unsigned charmaxing out at exactly255is why colors on your screen run from 0–255. That's not a coincidence — that's a data type showing up in your daily life.

Primary Data Type #2: float and double — The Decimal Duo

For numbers with fractional parts, C offers two precisions:

main.c
Run Online
float price = 19.99f;
// note the f suffixdouble pi = 3.141592653589793;
// no suffix needed
TypeSizePrecisionUse When
float4 bytes~7 significant digitsMemory is tight, precision isn't critical
double8 bytes~15 significant digitsDefault choice for decimals
long double10–16 byteseven moreSpecialized scientific work

⚠️The famous floating-point surprise:

main.c
Run Online
float f = 0.1f + 0.2f;
printf("%.20f\n", f);
// 0.30000001192092895508 — not exactly 0.3!

Computers store decimals in binary, and some fractions (like 0.1) can't be represented exactly — just like ⅓ can't be written exactly in decimal. This affectseverylanguage, but C shows it to you honestly.Practical rule:usedoubleby default, and never compare floats with==.

Primary Data Type #3: char — Small but Mighty

charstores asingle character— one byte, holding values from −128 to 127 (or 0 to 255 unsigned).

main.c
Run Online
char grade = 'A';
char initial = 'R';

But here's the secret that unlocks a dozen "aha" moments:a char is really a small integer wearing a costume.'A'is the number65underneath (its ASCII code), which means this genuinely works:

main.c
Run Online
char letter = 'A';
printf("%c\n", letter);
// A — as a character
printf("%d\n", letter);
// 65 — as a number!
printf("%c\n", letter + 1);
// B — yes, char arithmetic!

That last line — adding 1 to'A'to get'B'— is why C programmers can loop through the alphabet as easily as through numbers.

Primary Data Type #4: void — The Deliberate Nothing

voidmeans"no value here"— and it appears in two places:

main.c
Run Online
void printBanner() {
    // this function RETURNS nothing
    printf("=====\n");
}
void process(void) {
    // this function ACCEPTS nothing
    // ...
}

You'll also meetvoid*later — a "pointer to anything" — when you reach dynamic memory. For now, remember:voidis C's way of saying "empty on purpose."

The Complete Sizes & Ranges Reference Table

Bookmark this — it's the table every C programmer memorizes eventually:

Data TypeSize (typical)RangeFormat Specifier
char1 byte−128 to 127%c
unsigned char1 byte0 to 255%c/%u
short int2 bytes−32,768 to 32,767%hd
unsigned short2 bytes0 to 65,535%hu
int4 bytes±2.1 billion%d
unsigned int4 bytes0 to 4.2 billion%u
long int4–8 bytessystem-dependent%ld
long long int8 bytes±9.2 quintillion%lld
float4 bytes~7 digits precision%f
double8 bytes~15 digits precision%lf
long double10–16 bytes~19 digits precision%Lf

⚠️Important honesty note:C doesnotguarantee exact sizes — it guaranteesminimums. Anintis "at least 2 bytes," which is why old systems had 2-byte ints. Which raises the question: how do you know the size onyourmachine?

Ask Your Compiler: The sizeof Operator

C gives you a built-in detective —sizeof— that reports exactly how many bytes any type occupies onyoursystem:

main.c
Run Online
#include <stdio.h>
int main() {
    printf("char:   %zu byte\n", sizeof(char));
    printf("short:  %zu bytes\n", sizeof(short));
    printf("int:    %zu bytes\n", sizeof(int));
    printf("long:   %zu bytes\n", sizeof(long));
    printf("float:  %zu bytes\n", sizeof(float));
    printf("double: %zu bytes\n", sizeof(double));
    return 0;
}

Output on a typical modern system:

main.c
Run Online
char: 1 byte
short: 2 bytes
int: 4 bytes
long: 8 bytes
float: 4 bytes
double: 8 bytes

Run this on your own machine — the answers are your system's truth. (Fun fact:sizeofis a compile-timeoperator, not a function. One of the few keywords that does real work.)

When Types Overflow: The Odometer Effect

What happens when a value outgrows its type? C doesn't crash — itwraps around, like a car odometer rolling past its maximum:

main.c
Run Online
#include <stdio.h>
#include <limits.h>
int main() {
    int max = INT_MAX;
    // 2147483647
    printf("Max:     %d\n", max);
    printf("Max + 1: %d\n", max + 1);
    // -2147483648 — overflowed!
    return 0;
}

Add 1 to the largest possibleint, and you get themost negativeone. This is calledinteger overflow, and it has caused real disasters — including the famous 1996 Ariane 5 rocket explosion, where a 16-bit integer overflowed trying to hold a 64-bit velocity value. Data types aren't academic details. Sometimes they're the difference between orbit and debris.

How to Choose the Right Type (Decision Guide)

New programmers freeze here, so here's a simple decision path:

  • Whole number, normal size?→int
  • Whole number, huge or counting things?→long longorunsigned int
  • Decimal?→double(always, unless memory is critical →float)
  • Single character or byte-sized number?→char
  • Yes/no flag?→_Bool(orboolvia<stdbool.h>)

When in doubt:intfor counting,doublefor measuring. You'll be right 95% of the time.

Runnable C Code Example & Practical Implementation

main.c
Run Online
#include <stdio.h>
int main() {
    printf("char size:   %zu byte(s)\
", sizeof(char));
    printf("short size:  %zu byte(s)\
", sizeof(short));
    printf("int size:    %zu byte(s)\
", sizeof(int));
    printf("long size:   %zu byte(s)\
", sizeof(long));
    printf("float size:  %zu byte(s)\
", sizeof(float));
    printf("double size: %zu byte(s)\
", sizeof(double));
    printf("void* size:  %zu byte(s)\
", sizeof(void*));
    return 0;
}

Key Takeaways, Best Practices & Memory Safety Rules

Best Practice & Key Takeaways
Include `` and use explicit integer widths (`int32_t`, `uint64_t`) for binary protocols and portable file formats.

Frequently Asked Questions & Technical Interview Insights

Technical Interview & Viva Questions

Frequently asked C programming interview questions
Q

Q: Why is the exact byte size of `int` not identical on every machine in C?

A: C standard specifies only minimum ranges: `int` must be at least 16 bits. On 32/64-bit architectures it is typically 32 bits, while on 16-bit microcontrollers it is 16 bits.
Q

Q: How do you guarantee exact bit-width across platforms?

A: Use `` types like `int8_t`, `int16_t`, `int32_t`, `int64_t`, `uint32_t`.

Related Tools, Tutorials & Authoritative References

Recommended Interactive Tools

Authoritative Standards & Citations