Data Types in C: Basic, Derived and User-Defined Types

Data types in C define the type of data a variable can store and the amount of memory allocated to it. Understanding data types in C is one of the most important fundamentals for learning the C programming language, as it directly affects program efficiency, memory usage, and correctness.

C is a statically typed language, which means every variable must be declared with a specific data type before it is used. This blog explains all major data types in C with clear classification, examples, and practical explanations for beginners.

What Are Data Types in C?

In C programming, a data type specifies:

  • The type of value a variable can store

     

  • The size of memory allocated

     

  • The range of values allowed

     

  • The operations that can be performed on the data

     

Proper use of data types helps in writing efficient, optimized, and error-free programs.

Types of Data Types in C

C data types are broadly classified into four categories:

  1. Basic (Primitive) Data Types

     

  2. Derived Data Types

     

  3. User-Defined Data Types

     

  4. Void Data Type

     

Basic Data Types in C

Basic data types are the fundamental building blocks of C programming.

int Data Type

The int data type is used to store whole numbers without decimal points.

Example:

int number = 10;

  • Size: 2 or 4 bytes (depends on compiler)

     

  • Range: -32,768 to 32,767 (for 2 bytes)

     

float Data Type

The float data type stores decimal or fractional values.

Example:

float price = 99.99;

  • Size: 4 bytes

     

  • Precision: Up to 6 decimal places

     

double Data Type

The double data type is used for storing large decimal values with higher precision.

Example:

double distance = 12345.6789;

  • Size: 8 bytes

     

  • Precision: Up to 15 decimal places

     

char Data Type

The char data type stores a single character.

Example:

char grade = ‘A’;

  • Size: 1 byte

     

  • Range: -128 to 127 or 0 to 255

     

Derived Data Types in C

Derived data types are created using basic data types.

Array

An array stores multiple values of the same data type in a contiguous memory location.

Example:

int marks[5] = {80, 85, 90, 75, 88};

Pointer

Pointers store the memory address of another variable.

Example:

int x = 10;

int *ptr = &x;

Pointers are widely used for dynamic memory allocation and efficient data handling.

Structure

A structure allows grouping different data types under one name.

Example:

struct Student {

    int id;

    char name[20];

};

Structures are commonly used to represent real-world entities.

Union

A union is similar to a structure, but all members share the same memory location.

Example:

union Data {

    int i;

    float f;

};

Only one member can hold a value at a time.

User-Defined Data Types in C

User-defined data types allow programmers to define their own data types.

typedef

typedef is used to create an alias for an existing data type.

Example:

typedef unsigned int uint;

enum

An enumeration defines a set of named integer constants.

Example:

enum Days {Mon, Tue, Wed, Thu, Fri};

Enums improve code readability and maintainability.

Void Data Type

The void data type represents the absence of a value.

Common uses of void:

  • Functions that return no value

     

  • Generic pointers (void *)

     

Example:

void display() {

    printf(“Hello”);

}

Size of Data Types in C

The size of data types may vary depending on the compiler and system architecture.

Data Type

Size (Bytes)

char

1

int

2 or 4

float

4

double

8

Use the sizeof() operator to check size dynamically.

Why Data Types Are Important in C

  • Efficient memory utilization

     

  • Better performance

     

  • Improved program reliability

     

  • Clear data representation

     

Choosing the correct data type is critical for system-level and embedded programming.

Frequently Asked Questions (FAQs)

What is the most commonly used for numeric values.

What is the difference between float and double?

double provides higher precision and uses more memory than float.

What is a derived data type in C?

Derived data types are created from basic data types, such as arrays, pointers, and structures.

What is void data type used for?

It is used for functions that return no value and generic pointers.

Can data type size vary in C?

Yes, data type size depends on the compiler and system architecture.

Conclusion

Understanding data types in C is essential for writing efficient and reliable programs. From basic types like int and char to complex user-defined structures, data types form the foundation of C programming.

A strong grasp of data types helps developers manage memory effectively and build scalable applications.