Variables, Data Types & Operators
The basic building blocks — how C stores and manipulates values.
Data Types
C has basic data types: int (whole numbers), float and double (decimals), char (single character), and void (no value). Each type takes a fixed amount of memory — e.g. int is usually 4 bytes, char is 1 byte. Choosing the right type matters for both correctness and memory efficiency.
int age = 20;
float price = 99.5;
char grade = 'A';
double pi = 3.14159265;Variables & Declaration
A variable is a named memory location that holds a value of a specific type. In C, you must declare a variable's type before using it — this is called 'static typing', and it lets the compiler catch type errors early.
Operators
Arithmetic (+, -, *, /, %), Relational (==, !=, <, >), Logical (&&, ||, !), and Assignment (=, +=, -=) operators let you compute and compare values. The modulus operator (%) gives the remainder of division — very useful for checking even/odd numbers or cycling through values.
int a = 10, b = 3;
printf("%d", a % b); // prints 1 (remainder)🌍 Real-World Use
Every calculator app, billing system, or game score tracker relies on correctly chosen data types — using 'int' for a bank balance instead of 'float' can cause rounding errors that matter a lot with real money.
💡 Pro Tip
Watch out for 'integer division': 5 / 2 in C gives 2, not 2.5, because both operands are integers. If you need a decimal result, cast at least one operand to float: (float)5 / 2.
🧪 Quick Self-Test
Check what you just learned — no pressure, just practice.
1. What does the % operator return?
2. What is the result of 5 / 2 in C (both as int)?