Advertisement

Data Types in C

C Language Variables & Data Types 📅 May 2026 ⏱ 2 min read 🆓 Free

Data Types in C

A data type specifies: what kind of data a variable will store, how many bytes of memory to allocate, and what operations are allowed.

Primary Data Types with sizeof()

c
#include <stdio.h>

int main() {
    // ── Basic types ──────────────────────────────
    char       c  = 'A';           // character
    short      s  = 32000;         // small integer
    int        i  = 2147483647;    // regular integer
    long       l  = 1000000000L;   // large integer
    long long  ll = 9000000000LL;  // very large
    float      f  = 3.14f;         // 7-digit decimal
    double     d  = 3.14159265358; // 15-digit decimal
    
    // ── Print types and sizes ────────────────────
    printf("Type         Size    Value\n");
    printf("-------------------------------------------\n");
    printf("char       : %lu byte  | %c\n",  sizeof(c),  c);
    printf("short      : %lu bytes | %d\n",  sizeof(s),  s);
    printf("int        : %lu bytes | %d\n",  sizeof(i),  i);
    printf("long       : %lu bytes | %ld\n", sizeof(l),  l);
    printf("long long  : %lu bytes | %lld\n",sizeof(ll), ll);
    printf("float      : %lu bytes | %.2f\n",sizeof(f),  f);
    printf("double     : %lu bytes | %lf\n", sizeof(d),  d);
    
    return 0;
}
▶ Output
Type         Size    Value
-------------------------------------------
char       : 1 byte  | A
short      : 2 bytes | 32000
int        : 4 bytes | 2147483647
long       : 8 bytes | 1000000000
long long  : 8 bytes | 9000000000
float      : 4 bytes | 3.14
double     : 8 bytes | 3.141593

Complete Data Type Reference Table

TypeBytesRangeFormat SpecifierBest Used For
char1-128 to 127%cSingle characters, ASCII codes
unsigned char10 to 255%c / %hhuByte values, small positive numbers
short2-32,768 to 32,767%hdSmall integers
int4-2.1B to 2.1B%dRegular whole numbers (age, count, marks)
unsigned int40 to 4.2B%uPositive-only numbers (size, count)
long8Very large%ldLarge whole numbers
float47-digit precision%fPrices, temperatures, weights
double815-digit precision%lfScientific, financial calculations
long double1618-digit precision%LfExtreme precision required
📌 Note: sizeof() returns the size in bytes on YOUR specific machine. Sizes can differ between 32-bit and 64-bit systems.
Advertisement
← Back to C Language Index