What are Data Types in C?

In C, data types define the type of data that a variable can store. They help the compiler understand how much memory is needed and what type of operations can be performed on the data.

For example, integers are used for whole numbers, characters are used for single letters, and floating-point types are used for decimal values. Choosing the correct data type helps in efficient memory usage and avoids errors.

Example:


int age = 20;             // Integer
float height = 5.7;       // Decimal value
double salary = 45678.98; // Double precision decimal
char grade = 'A';         // Character
        

Why Use Data Types?

  • To efficiently manage memory.
  • To store different kinds of values correctly.
  • To perform valid operations on data.
  • To improve program accuracy and performance.

Types of Data Types in C

Data types in C are mainly divided into the following categories:

  1. Basic (Primary) Data Types
  2. Derived Data Types
  3. User-defined Data Types
  4. Void Data Type

1. Basic (Primary) Data Types

These are the fundamental data types used in C programming. They store simple values such as integers, decimal numbers, and characters.

Basic Data Types in C:

  • int – stores whole numbers.
  • float – stores decimal numbers (single precision).
  • double – stores decimal numbers with higher precision.
  • char – stores a single character.

Memory Size and Range of Basic Data Types

Data Type Size (in Bytes) Range (Approximate) Example
int 4 -2,147,483,648 to 2,147,483,647 int age = 20;
float 4 ±3.4e−38 to ±3.4e+38 float marks = 89.5;
double 8 ±1.7e−308 to ±1.7e+308 double salary = 45000.75;
char 1 -128 to 127 char grade = 'A';

Example of Basic Data Types

#include <stdio.h>

int main() {

    int rollNo = 101;
    float percentage = 92.5;
    double bankBalance = 123456.789;
    char grade = 'A';

    printf("Roll No: %d\n", rollNo);
    printf("Percentage: %.1f%%\n", percentage);
    printf("Bank Balance: %.3lf\n", bankBalance);
    printf("Grade: %c\n", grade);

    return 0;
}

Output:

Roll No: 101

Percentage: 92.5%

Bank Balance: 123456.789

Grade: A

Explanation:

  • int stores whole numbers such as roll number.
  • float stores decimal values like percentage.
  • double stores large decimal numbers with more precision.
  • char stores a single character.
  • %d is the format specifier used for integers.
  • %f is used for float values.
  • %lf is used for double values.
  • %c is used for characters.

2. Derived Data Types

Derived data types are created using basic data types.

  • Arrays – collection of similar data elements.
  • Pointers – store memory addresses.
  • Functions – blocks of reusable code.

Example:


int numbers[5] = {1, 2, 3, 4, 5};   // Array
int *ptr = &numbers[0];             // Pointer
        

3. User-defined Data Types

These data types are created by programmers according to program requirements.

  • struct – groups different types of data together.
  • union – shares memory among members.
  • enum – stores named integer constants.
  • typedef – creates a new name for an existing data type.

Example:

struct Student {
    int rollNo;
    char name[50];
    float marks;
};

enum Day {MON, TUE, WED};

typedef unsigned int uint;

4. Void Data Type

The void data type represents “no value”. It is mainly used in functions that do not return anything.

void display() {
    printf("Hello Students");
}

Summary:

  • Data types define what kind of value a variable can store.
  • Basic data types include int, float, double, and char.
  • Derived data types are created from basic types.
  • User-defined data types are created by programmers.
  • Void represents no value.
  • Correct data type selection improves memory efficiency and program accuracy.

Welcome to ShikshaSanchar!

ShikshaSanchar is a simple and helpful learning platform made for students who feel stressed by exams, assignments, or confusing topics. Here, you can study with clarity and confidence.

Here, learning is made simple. Notes are written in easy English, filled with clear theory, code examples, outputs, and real-life explanations — designed especially for students like you who want to understand, not just memorize.

Whether you’re from school, college, or someone learning out of curiosity — this site is for you. We’re here to help you in your exams, daily studies, and even to build a strong base for your future.

Each note on this platform is carefully prepared to suit all levels — beginner to advanced. You’ll find topics explained step by step, just like a good teacher would do in class. And the best part? You can study at your pace, anytime, anywhere.

Happy Learning! – Team ShikshaSanchar