In C, data types define what kind of data a variable can hold and how much space it takes up in memory. Think of them as containers of different sizes and shapes.
C data types are generally split into three categories: Basic, Derived (like arrays and pointers), and User-defined (like the struct and union we discussed).
Data TypeKeywordSize (Approx)Range / Use
Integer
int4 bytesWhole numbers (e.g., -5, 42)Character
char1 byteSingle characters/ASCII (e.g., 'A', '$')
#include <stdio.h>
int main() {
// Basic types
int age = 25;
float salary = 4500.50;
double distance = 1234567.8910;
char grade = 'A';
// Modifiers
unsigned int positiveOnly = 500;
long long hugeNumber = 9223372036854775807LL;
printf("Integer: %d\n", age);
printf("Float: %.2f\n", salary);
printf("Double: %.4lf\n", distance);
printf("Character: %c\n", grade);
printf("Unsigned: %u\n", positiveOnly);
printf("Long Long: %lld\n", hugeNumber);
return 0;
}Expected output:
Integer: 25
Float: 4500.50
Double: 1234567.8910
Character: A
Unsigned: 500
Long Long: 9223372036854775807