Ever wondered how your computer knows the difference between a number and a word? That’s where data types in C come in. In simple words, data types help your program understand what kind of data it's working with, such as age, name, temperature, etc.
Whether you're building a calculator or a game, data types in C play a key role. In this article, you’ll learn about the types of data types in C, how they work, when to use which, and how to avoid common mistakes. By the end, you'll be writing clean and bug-free code like a pro!

Imagine you're in a kitchen. You don’t pour soup into a plate or chop veggies in a glass, right? You use different containers based on what you're handling. That’s exactly how data types in C work. They’re like containers for your data.
So, when you declare a variable in C, you're telling your program what you’ll store and how much space it needs.
Understanding data types in C is like getting a superpower because it helps you code faster, smarter, and with fewer errors.
Whether you're storing:
Choosing the right type ensures your program runs smoothly. It’s a small step that makes a huge difference in real-world coding projects.
Let’s now explore the basic data types in C. These are your must-know types if you're just starting.
Used for counting things like age, score, or number of apples.
Copy Code
#include <stdio.h>
int main() {
int age = 15;
printf("Age: %d", age);
return 0;
}
Output:
Age: 15✔ Great for: roll numbers, total items, scores
Used for values with decimal points, like price or temperature.
Copy Code
#include <stdio.h>
int main() {
float temperature = 36.5;
printf("Temperature: %.1f", temperature);
return 0;
}
Output:
Temperature: 36.5✔ Great for: height, temperature, percentages
Store one character, such as the first letter of your name.
Copy Code
#include <stdio.h>
int main() {
char grade = 'A';
printf("Grade: %c", grade);
return 0;
}
Output:
Grade: A✔ Great for: grades, initials, single characters
Used when your function doesn’t return anything.
Copy Code
#include <stdio.h>
void greet() {
printf("Hello!");
}
int main() {
greet();
return 0;
}
Output:
Hello!✔ Great for: when nothing is returned from a function
Think of modifiers like power-ups in a video game. The data type remains the same, but it becomes stronger or bigger.
C has these modifiers:
These change how much memory a variable uses and what range of numbers it can store
Example:
Copy Code
#include <stdio.h>
int main() {
unsigned int score = 300;
printf("Score: %u", score);
return 0;
}
Output:
Score: 300✔ unsigned means no negative numbers allowed.
| Modifier | Size (Bytes) | Range |
| int | 4 | -2,147,483,648 to 2,147,483,647 |
| unsigned int | 4 | 0 to 4,294,967,295 |
| short int | 2 | -32,768 to 32,767 |
| long int | 8 | Very large numbers |
They help you save memory or store more data, so it’s important to choose wisely.
As your programs grow, you need smarter tools. That's where derived data types come in.
They help you:
Copy Code
#include <stdio.h>
int main() {
int marks[5] = {80, 85, 90, 70, 88};
printf("Third mark: %d", marks[2]);
return 0;
}
Output:
Third mark: 90➔ Use when storing multiple values of the same type.
Pointers store memory addresses. A little advanced, but super useful.
Copy Code
#include <stdio.h>
int main() {
int a = 10;
int *ptr = &a;
printf("Value at ptr: %d", *ptr);
return 0;
}
Output:
Value at ptr: 10➔ Great for advanced memory management
A function helps avoid writing the same code again and again.
Copy Code
#include <stdio.h>
void hello() {
printf("Hi from the function!");
}
int main() {
hello();
return 0;
}
Output:
Hi from the function!➔ Use functions for cleaner, reusable code
Sometimes, the basic types just aren’t enough. When you want to customize how data is grouped and stored, user-defined data types in C come in handy.
These help you organize complex data better. Let’s look at the 3 main types with fun, real-life examples.
A struct is used to group different data types under one name
Copy Code
#include <stdio.h>
struct Student {
char name[20];
int marks;
};
int main() {
struct Student s1 = {"Aman", 92};
printf("Name: %s\nMarks: %d", s1.name, s1.marks);
return 0;
}
Output:
makefile
CopyEdit
Name: Aman
Marks: 92✔ Use when different types of data belong together.
A union is similar to a struct, but it saves memory by storing only one value at a time.
Copy Code
#include <stdio.h>
union Data {
int i;
float f;
};
int main() {
union Data d;
d.i = 10;
printf("Int: %d", d.i);
return 0;
}
Output:
Int: 10✔ Use when you want to save space and only need one value at a time.
Use enum when you have a list of related constants.
Copy Code
#include <stdio.h>
enum Days { MON, TUE, WED };
int main() {
enum Days today = TUE;
printf("Today is day number: %d", today);
return 0;
}
Output:
Today is day number: 1✔ Use for categories like colors, days, directions
Each data type uses some memory and can only store values within a certain range. This matters a lot when you're working with big or small numbers.
You can use the sizeof operator in C to find out how much memory your variable is using.
Copy Code
#include <stdio.h>
int main() {
printf("Size of int: %lu bytes", sizeof(int));
return 0;
}
| Data Type | Size (Bytes) | Range |
| char | 1 | -128 to 127 |
| unsigned char | 1 | 0 to 255 |
| int | 4 | -2,147,483,648 to 2,147,483,647 |
| unsigned int | 4 | 0 to 4,294,967,295 |
| float | 4 | ~±3.4E-38 to ±3.4E+38 |
| double | 8 | ~±1.7E-308 to ±1.7E+308 |
➔ Always check this before picking a data type!
Let’s say you put 500 in a char variable. It’s like trying to pour 2 liters into a 1-liter bottle. This causes overflow.
Copy Code
#include <stdio.h>
int main() {
char x = 150;
printf("x = %d", x);
return 0;
}
Output: May show unexpected or wrong value⚠︎ Be careful! Giving a value too big for its container can crash your code or give wrong results. In some cases, this even causes Segmentation Faults, which means your program tries to access memory it shouldn’t.
Here are some quick rules to help you avoid mistakes:
Making smart choices keeps your code fast, safe, and memory-efficient.
Let’s check how much you remember. Try these in your C compiler:
🛠️ The more you practice, the better you get!
In C programming, data types define the kind of data a variable can store. The four main data types in C are int, float, char, and void. Choosing the right data type helps optimize memory and avoid errors. Advanced types like struct, array, and enum make code cleaner and more powerful.
You’ve now explored all the major data types in C, from basic to advanced. You’ve learned how to use them, when to use them, and what mistakes to avoid.
Want to become a better coder? Mastering data types is your first big step.
Now open your compiler and start practicing. Because practice turns knowledge into skill.
You're all set to take your first real step into the world of C programming. Your journey to becoming a confident coder starts now!
Q1. What are the 4 basic data types in C?
int, float, char, and void are the four basic data types.
Q2. What happens if I assign a big number to a short variable?
It causes overflow. The value may wrap around or give unexpected results.
Q3. What’s the difference between float and double in C?
Both store decimal numbers, but double has more precision and range than float.
Q4. Can I change the data type after declaring a variable?
No. Once declared, a variable keeps its data type. You need to declare a new one if needed.
Q5. What is the void data type used for in C?
void means no data. It’s used when a function doesn’t return anything.
Practice small programs every day using different data types. Save this guide so you can come back to it anytime. And always remember, choosing the right data type makes your code smarter!
Personalized learning paths with interactive materials and progress tracking for optimal learning experience.
Explore LMSCreate professional, ATS-optimized resumes tailored for tech roles with intelligent suggestions.
Build ResumeDetailed analysis of how your resume performs in Applicant Tracking Systems with actionable insights.
Check ResumeAI analyzes your code for efficiency, best practices, and bugs with instant feedback.
Try Code ReviewPractice coding in 20+ languages with our cloud-based compiler that works on any device.
Start Coding
TRENDING
BESTSELLER
BESTSELLER
TRENDING
HOT
BESTSELLER
HOT
BESTSELLER
BESTSELLER
HOT
POPULAR