
Data Types in C
In C, data types define the type and size of data a variable can store — like integers, characters, or floating-point numbers. They're essential for memory efficiency and type safety. ??
? Basic Data Types in C
char letter = 'A';
Stored as ASCII value (
'A'
= 65)
? Floating Point Types
float pi = 3.14f;double g = 9.80665;
Type | Precision |
---|---|
float | ~6-7 digits |
double | ~15 digits |
? Example Code
#include <stdio.h>int main() { int age = 25; float height = 5.9; char grade = 'A'; printf("Age: %d\n", age); printf("Height: %.1f\n", height); printf("Grade: %c\n", grade); return 0;}
? Type Modifiers
C supports modifiers to extend or limit ranges:
signed
,unsigned
short
,long
Example:
unsigned int score = 150;long long bigNumber = 123456789012345;
? Summary
Use the right data type to save memory and avoid bugs
Combine with
sizeof()
to check memory sizeUnderstand type conversions (implicit/explicit)