Table of Contents

    Data Types in C Programming: Overview and Examples

    A datatype is a special keyword used to allocate sufficient memory space for the data, in other words, Data type is used for representing the data in main memory (RAM) of the computer. Data types represent the different values to be stored in the variable. Every data type has a range of values. The compiler allocates memory space for each variable or constant according to its data type.

    Each variable in C has an associated data type. Each data type requires different amounts of memory and has some specific operations which can be performed over it. Let us briefly describe them one by one:

    Datatypes in C Programming

    Data types in C

    Primary data types

    1. Integer Types
    2. Floating-point Types
    3. Character Types

    Enumerated types

    1. enum

    Derived data types

    1. Arrays
    2. Pointer
    3. Structure
    4. Union

    void

    1. void
    Datatypes in c programming
    Types Data Types
    Basic Data Type int, char, float, double
    Derived Data Type array, pointer, structure, union
    Enumeration Data Type enum
    Void Data Type void

    Following are the examples of some very common data types used in C:

    char: The most basic data type in C. It stores a single character and requires a single byte of memory in almost all compilers.
    int: As the name suggests, an int variable is used to store an integer.
    float: It is used to store decimal numbers (numbers with floating point value) with single precision.
    double: It is used to store decimal numbers (numbers with floating point value) with double precision.

    Primary data types

    Integer Types

    • short
    • int
    • long

    Floating-point Types

    • float
    • double

    Character Types

    • char
    Primary DataType in C

    Primary Datatype or Basic Datatype

    The memory size of basic data types may change according to 32 or 64 bit operating system. Let's see the basic data types. Its size is given according to 32 bit architecture.

    Integer Type Datatype

    Data Types Memory Size Range
    int 2 byte ?32,768 to 32,767
    signed int 2 byte ?32,768 to 32,767
    unsigned int 2 byte 0 to 65,535
    short int 2 byte ?32,768 to 32,767
    signed short int 2 byte ?32,768 to 32,767
    unsigned short int 2 byte 0 to 65,535
    long int 4 byte -2,147,483,648 to 2,147,483,647
    signed long int 4 byte -2,147,483,648 to 2,147,483,647
    unsigned long int 4 byte 0 to 4,294,967,295

    Floating-points Datatypes

    Type Storage size Value range Precision
    float 4 byte 1.2E-38 to 3.4E+38 6 decimal places
    double 8 byte 2.3E-308 to 1.7E+308 15 decimal places
    long double 10 byte 3.4E-4932 to 1.1E+4932 19 decimal places

    Character Types Datatypes

    Data Types Memory Size Range
    char 1 byte ?128 to 127
    signed char 1 byte ?128 to 127
    unsigned char 1 byte 0 to 255

    sizeof(DataType) Operator

    To get the exact size of a type or a variable on a particular platform, you can use the sizeof operator.

    To get the exact size of a type or a variable on a particular platform, you can use the sizeof operator.

    // Run on 64 bit Machine
    
    #include
    int main() {
    
       printf("Storage size for int : %d \n", sizeof(int));
       
       return 0;
    }
    Storage size for int : 4
    Press any key to continue . . .

    Calculate Range

    // Run on 64 bit Machine
    
    #include 
    #include 
    
    int main() {
    
       printf("Storage size for float : %d \n", sizeof(float));
       printf("Minimum float positive value: %E\n", FLT_MIN );
       printf("Maximum float positive value: %E\n", FLT_MAX );
       printf("Precision value: %d\n", FLT_DIG );
       
       return 0;
     }
    Storage size for float : 4
    Minimum float positive value: 1.175494E-038
    Maximum float positive value: 3.402823E+038
    Precision value: 6
    Press any key to continue . . .
    Practice Quiz 36 MCQs Smart Learning

    Master This Topic with Smart Practice

    Reinforce what you just learned by solving high-quality MCQs. Improve accuracy, boost confidence, and prepare like a topper.

    Topic-wise MCQs
    Instant Results
    Improve Accuracy
    Exam Ready Practice
    Login & Start Quiz Create Free Account
    Save progress • Track results • Learn faster