Open In App

Data Types in C

Last Updated : 18 Oct, 2025
Comments
Improve
Suggest changes
490 Likes
Like
Report

Each variable in C has an associated data type. It specifies the type of data that the variable can store like integer, character, floating, double, etc.

C is a statically type language where each variable's type must be specified at the declaration and once specified, it cannot be changed.

data_type_in_c

In this article, we will discuss the basic (primary) data types in C.

C++
#include <stdio.h>

int main()
{
    // integer
    int age = 20;

    // floating-point
    float height = 5.7;

    // double-precision floating-point
    double pi = 3.14159;

    // character
    char grade = 'A';

    printf("Age: %d\n", age);
    printf("Height: %.1f\n", height);
    printf("Pi: %.5lf\n", pi);
    printf("Grade: %c\n", grade);

    return 0;
}

Output
Age: 20
Height: 5.7
Pi: 3.14159
Grade: A

Integer Data Type

  • Stores whole numbers (positive, negative, or zero).
  • We use int keyword to declare the integer variable:
  • Size: 4 bytes, Range: -2,147,483,648 to 2,147,483,647.
  • Format specifier: %d.

Format specifiers are the symbols that are used for printing and scanning values of given data types.

C++
#include <stdio.h>

int main() {
    int var = 22;
    
    printf("var = %d", var);
    return 0;
}

Output
var = 22

Character Data Type

  • Stores a single character (like ‘A’, ‘b’, or ‘5’).
  • Size: 1 byte, Range: -128 to 127 (signed by default).
  • Format specifier: %c.
C++
#include <stdio.h>

int main() {
    char ch = 'A';
    
    printf("ch = %c", ch);
    return 0;
}

Output
ch = A

Float Data Type

  • Stores decimal numbers (numbers with fractional part).
  • Size: 4 bytes, Approximate range: 3.4e-38 to 3.4e+38.
  • Format specifier: %f.
C++
#include <stdio.h>

int main() {
    float val = 12.45;
    
    printf("val = %f", val);
    return 0;
}

Output
val = 12.450000

Double Data Type

  • Stores decimal numbers with more precision than float.
  • Size: 8 bytes, Approximate range: 1.7e-308 to 1.7e+308.
  • Format specifier: %lf.
C++
#include <stdio.h>

int main() {
    double val = 1.4521;
    
    printf("val = %lf", val);
    return 0;
}

Output
val = 1.452100

Void Data Type

  • Represents no value or empty type.
  • Used in functions that do not return any value.
  • Can also be used for generic pointers (void *) in memory operations.
C++
#include <stdio.h>

// Function with void return type
void greet()
{
    printf("Hello, welcome!\n");
}

int main()
{
    greet();
    return 0;
}

Output
Hello, welcome!

Size of Data Types in C

The size of the data types in C is dependent on the size of the architecture, so we cannot define the universal size of the data types. For that, the C language provides the sizeof() operator to check the size of the data types.

C
#include <stdio.h>

int main()
{

    // Use sizeof() to know size the data types
    printf("The size of int: %d\n", sizeof(int));
    printf("The size of char: %d\n", sizeof(char));
    printf("The size of float: %d\n", sizeof(float));
    printf("The size of double: %d", sizeof(double));

    return 0;
}

Output
The size of int: 4
The size of char: 1
The size of float: 4
The size of double: 8

Different data types also have different ranges up to which can vary from compiler to compiler. If you want to know more about ranges refer to this Ranges of Datatypes in C.

Note: The long, short, signed and unsigned are datatype modifier that can be used with some primitive data types to change the size or length of the datatype.

Literals in C

In C, literals are constant values assigned to variables. They represent fixed values that cannot be changed. Literals occupy memory but do not have references like variables. Often, the terms constants and literals are used interchangeably.

Type Conversion

In C, type conversion is the process of changing one data type into another. This can happen automatically by the compiler or manually by the programmer. Type conversion is only performed between data types where such a conversion is possible.


Data types in C
Visit Course explore course icon
Video Thumbnail

Data types in C

Video Thumbnail

Ranges of Data Types in C

Explore