Industrial manufacturing
Industrial Internet of Things | Industrial materials | Equipment Maintenance and Repair | Industrial programming |
home  MfgRobots >> Industrial manufacturing >  >> Industrial programming >> C Language

C Data Types Explained: int, float, char, and More – A Complete Guide

C Data Types

This tutorial demystifies the fundamental data types in C—int, float, char, and others—so you can write precise, efficient code.

Video: Data Types in C Programming

In C, every variable is declared with a data type that defines its size and value range. For example:

int myVar;

Here, myVar is an int (integer) variable, typically occupying 4 bytes.


Basic Types

Below is a quick reference for the most commonly used C data types.

Type Size (bytes) Format Specifier
intat least 2, usually 4%d, %i
char1%c
float4%f
double8%lf
short int2 usually%hd
unsigned intat least 2, usually 4%u
long intat least 4, usually 8%ld, %li
long long intat least 8%lld, %lli
unsigned long intat least 4%lu
unsigned long long intat least 8%llu
signed char1%c
unsigned char1%c
long doubleat least 10, usually 12 or 16%Lf

int

An int represents whole numbers—zero, positives, and negatives—without decimal points. Typical examples include 0, -5, and 10.

Declare an integer variable like this:

int id;

The variable id now holds an integer. You can also declare multiple integers simultaneously:

int id, age;

On most platforms, int is 4 bytes (32 bits) and can represent 232 distinct values ranging from –2,147,483,648 to 2,147,483,647.


float and double

Use float and double to store real (floating‑point) numbers.

float salary;
double price;

Both types support scientific notation, e.g.,

float normalizationFactor = 22.442e2;

Key difference: float (single precision) occupies 4 bytes, whereas double (double precision) occupies 8 bytes.


char

The char keyword declares a single character variable. Example:

char test = 'h';

Its size is exactly 1 byte.


void

void represents the absence of type. It’s used for functions that return no value:

void printMessage() {
    printf("Hello, world!\n");
}

You cannot create variables of type void.


short and long

When you need a larger numeric range, use long or long long:

long a;
long long b;
long double c;

For small integer ranges (–32,767 to 32,767), short suffices:

short d;

Check a type’s size with sizeof():

#include <stdio.h>
int main() {
    short a;
    long b;
    long long c;
    long double d;

    printf("size of short = %d bytes\n", sizeof(a));
    printf("size of long = %d bytes\n", sizeof(b));
    printf("size of long long = %d bytes\n", sizeof(c));
    printf("size of long double= %d bytes\n", sizeof(d));
    return 0;
}

signed and unsigned

Modifiers that control a type’s value range:

Examples:

// valid
unsigned int x = 35;
int y = -35;  // signed int
int z = 36;   // signed int

// invalid – unsigned cannot hold negative numbers
unsigned int num = -35;

With a 4‑byte int, y spans –231 to 231‑1, while x spans 0 to 232‑1.


Derived Data Types

Derived types build on fundamental types: arrays, pointers, structures, and functions. Further tutorials will cover these in depth.


C Language

  1. Master C# Variables & Primitive Data Types: A Complete Guide
  2. Understanding C++ Data Types: Fundamentals, Modifiers, and Best Practices
  3. Four Proven Patterns for User‑Defined Functions in C
  4. Mastering Python Data Types: A Practical Guide
  5. Java Primitive Data Types: A Complete Guide with Examples
  6. C# Data Types Explained: Int, Double, Bool, String & More
  7. Verilog Data Types: Bits, Wires, and Logic Values Explained
  8. Understanding C Data Types: A Comprehensive Guide
  9. Understanding MATLAB Data Types: A Comprehensive Guide
  10. Comprehensive Guide to C# Data Types: Value, Reference, and Pointer