Data Types in C
A data type defines what kind of data a variable can store. It helps the compiler understand how much memory to allocate and what operations are allowed on that data. Think of data types like different containers — a water bottle stores liquids, a box stores solids. Similarly,int stores whole numbers, float stores decimals, and char stores characters. Choosing the right data type means efficient memory use.
Categories of Data Types
Primitive Data Types
Integer (int)
- Stores whole numbers (positive, negative, or zero)
- Can be
signed(default) orunsigned - Size: 4 bytes
- Range (signed): −2,147,483,648 to 2,147,483,647
- Range (unsigned): 0 to 4,294,967,295
- Signed: min = −2^(n−1), max = 2^(n−1) − 1
- Unsigned: min = 0, max = 2^n − 1
Character (char)
- Stores a single character enclosed in single quotes:
'A','z','3' - Internally stored as its ASCII value (an integer)
- Size: 1 byte
- Range (signed): −128 to 127 | Range (unsigned): 0 to 255
char:
- Attendance:
'P'for Present,'A'for Absent - Voting:
'Y'for Yes,'N'for No - Product sizes:
'S','M','L'
Float (float)
- Stores decimal numbers with single precision (~6–7 significant digits)
- Size: 4 bytes | Range: 1.2E−38 to 3.4E+38
- Used when decimal values are needed but high precision isn’t critical
Double (double)
- Stores decimal numbers with double precision (~15–16 significant digits)
- Size: 8 bytes | Range: 1.7E−308 to 1.7E+308
long doubleprovides even higher precision (10–16 bytes)
double:
Void (void)
void represents no value. It has three main uses:
- No return type:
void display()— function returns nothing - Void pointer:
void *ptr— can hold address of any type - No parameters:
int main(void)— function takes no arguments