This content originally appeared on DEV Community and was authored by M R Tuhin
Whether you’re starting with C or brushing up your knowledge, understanding data types is foundational. Here’s your quick yet deep dive into C Data Typesβall in one shot!
What are Data Types in C?
Data types in C tell the compiler what kind of data a variable will store (e.g., integers, characters, floating points). They’re essential for memory management, type checking, and operations.
Type Modifiers
C provides modifiers to adjust the size/range of base types:
short int // Smaller integer
long int // Larger integer
unsigned int // Only positive
signed int // Includes negative
Example:
unsigned int age = 25;
short int temp = -30;
long int population = 1000000;
Enumeration (enum)
Used to define a set of named constants.
enum week {Mon, Tue, Wed};
Tips
Always choose the smallest data type that fits your needs.
Use sizeof() to check memory usage.
Prefer unsigned when negative values are not needed for optimization.
Example Code
#include <stdio.h>
int main() {
int age = 20;
float gpa = 3.75;
char grade = 'A';
const int MAX = 100;
printf("Age: %d\n", age);
printf("GPA: %.2f\n", gpa);
printf("Grade: %c\n", grade);
printf("Max value: %d\n", MAX);
return 0;
}
Final Words
Understanding data types helps you write efficient, safe, and fast programs in C. Keep practicing by using different types in small programs.
Got a question? Drop it in the comments! Happy Coding!
This content originally appeared on DEV Community and was authored by M R Tuhin