What Is Data Type in C: Types and Examples

If you’re starting your journey into C programming, one of the first things you’ll encounter is the concept of data types. It might seem like a small thing at first glance — just picking a label for your variables — but trust me, choosing the right data type is one of the most important decisions you’ll make in any program.

In simple terms, data types define what kind of value a variable can hold — whether it's an integer, a character, a decimal, or even something more complex. Without them, your code wouldn’t know how to store or process the information it’s working with.

What Is Data Type in C: Types and Examples

This article will walk you through what is data type in C, the different types available, real-world examples, and why it all matters. We’ll also give you the inside scoop on how you can learn this and much more through the Data Structures and C Programming Course by Uncodemy.

What is Data Type in C?

Let’s answer the question directly:
 What is data type in C?

In C programming, a data type tells the compiler what kind of data a variable is intended to store. It defines the size of memory allocated to that variable and how the bits will be interpreted — as numbers, characters, or floating-point values.

Think of it this way: when you tell a friend to store an item, they need to know if it’s a book, a fruit, or a USB drive — because the container depends on the item. Similarly, in C, your computer needs to know what type of data you're storing, so it can choose the right “container” or memory format.

Why Are Data Types Important?

If C didn’t have data types, every value would just be a meaningless pile of bits. You wouldn't know whether 65 represents a character, a number, or something else. Data types bring clarity, structure, and predictability to your program.

Here’s what they help you with:

  • Efficient memory use: Only the required memory is allocated.
     
  • Error prevention: Type mismatches are flagged by the compiler.
     
  • Improved readability: Helps other developers understand what your variable is meant for.
     
  • Performance: Correct types help the system perform better by avoiding unnecessary conversions.

Categories of Data Types in C

C provides a range of data types, categorized into:

  1. Primary (or Built-in) Data Types
     
  2. Derived Data Types
     
  3. User-Defined Data Types
     
  4. Void Data Type

Let’s look into each category in detail.

1. Primary (Built-in) Data Types

These are the foundational types C offers. You’ll use these 90% of the time.

a. int (Integer)

Stores whole numbers, both positive and negative.

Copy Code

c

CopyEdit

int age = 25;
  • Size: Typically 4 bytes
     
  • Range: -2,147,483,648 to +2,147,483,647
     

b. float (Floating Point)

Used for numbers with decimal points.

Copy Code

c

CopyEdit

float height = 5.9;
  • Size: 4 bytes
     
  • Precision: Up to 6 decimal places
     

c. double (Double Precision Floating Point)

Used when higher precision is needed than float.

Copy Code

c

CopyEdit

double pi = 3.1415926535;
  • Size: 8 bytes
     
  • Precision: Up to 15 decimal places
     

d. char (Character)

Stores a single character. Characters are stored as ASCII values.

Copy Code

c

CopyEdit

char grade = 'A';
  • Size: 1 byte
     
  • Range: -128 to 127 (ASCII)

2. Derived Data Types

These are derived from the built-in types and allow complex storage.

a. Array

An array stores a fixed-size sequential collection of elements of the same data type.

Copy Code

c

CopyEdit

int scores[5] = {90, 80, 70, 85, 75};

b. Pointer

Stores the memory address of another variable.

Copy Code

c

CopyEdit

int x = 10;

int *ptr = &x;

c. Function

In C, functions are technically derived data types because they return values of some specific type.

Copy Code

c

CopyEdit

int add(int a, int b) {

    return a + b;

}

3. User-Defined Data Types

C lets you define your own data types using these constructs:

a. struct (Structure)

Used to group different data types under a single name.

Copy Code

c

CopyEdit

struct Student {

    char name[50];

    int age;

    float gpa;

};

b. union

Similar to structures, but all members share the same memory space.

Copy Code

c

CopyEdit

union Data {

    int i;

    float f;

};

c. typedef

Gives a new name to an existing type to improve code readability.

Copy Code

c

CopyEdit

typedef unsigned int age;

Now age is an alias for unsigned int.

d. enum (Enumeration)

Used for variables that can take one of a few predefined constants.

Copy Code

c

CopyEdit

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

4. Void Data Type

This type indicates no value or empty. It’s commonly used in two places:

  • Function return type when nothing is returned.
     
  • Generic pointer (i.e., void *).

Copy Code

c

CopyEdit

void greet() {

    printf("Hello!");

}

Data Type Modifiers in C

C allows modification of data types using shortlongsigned, and unsigned. These modifiers adjust the size or the range.

a. short int

Takes less memory.

Copy Code

c

CopyEdit

short int x = 100;

b. long int

Used for larger numbers.

Copy Code

c

CopyEdit

long int population = 1000000;

c. unsigned int

Only stores positive values, doubling the positive range.

Copy Code

c

CopyEdit

unsigned int age = 30;

d. signed int

Default. Stores both positive and negative values.

Examples and Use Cases

Let’s look at how different data types are used in real-life programming.

Example 1: Age Calculator

Copy Code

c

CopyEdit

int currentYear = 2025;

int birthYear = 2000;

int age = currentYear - birthYear;

Here, all values are whole numbers, so int is the best choice.

Example 2: Temperature Logger

Copy Code

c

CopyEdit

float temperature = 36.7;

For storing temperatures, float is perfect due to decimal precision.

Example 3: Student Grade Record

Copy Code

c

CopyEdit

char grade = 'A';

Characters like grades are stored using char.

Example 4: Complex Data

Copy Code

c

CopyEdit

struct Book {

    char title[100];

    float price;

    int pages;

};

To manage a book’s info, a struct groups different types.

Mistakes to Avoid When Choosing Data Types

  • Using float for currency: Always use double for financial calculations due to precision.
     
  • Not using unsigned for always-positive values: Like age or count.
     
  • Forgetting memory limits: A char can’t store a number like 300.
     
  • Using wrong type in loops: Always match the counter type with the loop requirement.

How to Practice Data Types Effectively?

Knowing the theory is just half the job. To really grasp data types:

  • Write programs that involve different types.
     
  • Mix types in functions and see how typecasting works.
     
  • Use debuggers to view how values are stored in memory.
     

And if you're serious about learning C the right way, check this out:

Learn C Programming with Uncodemy

If you want to dive deep into C, explore advanced data types, work on real-time projects, and build a solid programming foundation, then the C Programming Course by Uncodemy is for you.

🎓 Course Highlights:

  • Beginner to Advanced topics
     
  • Real-world examples and assignments
     
  • Interview-focused modules
     
  • Certificate on completion
     

🔗 Explore Uncodemy’s C Programming Course

Whether you're prepping for an internship, a coding competition, or your college exams, this course makes data types — and the rest of C — easy to master.

Final Thoughts

Understanding what is data type in C is more than just learning some definitions. It’s about learning how your program thinks, stores, and manipulates data. Each data type brings its own strengths and limitations — and the better you understand them, the cleaner and more efficient your code becomes.

From managing memory smartly to avoiding silly bugs, data types play a role in every aspect of programming. So next time you write int or char, remember — you're telling your computer exactly how to think about that variable.

Choose wisely, code wisely.

Placed Students

Our Clients

Partners

...

Uncodemy Learning Platform

Uncodemy Free Premium Features

Popular Courses