Nearby lessons
19 of 124C - Data Types
Data Types is one of the foundational topics in C programming. This lesson explains The Basic Data Types — Each One in Its Own Program, Program 1: int (whole numbers) and Program 2: float (decimal numbers) with complete, runnable code examples, clear step-by-step explanations, and common mistakes to avoid with exam-style MCQs at the end.
The Basic Data Types — Each One in Its Own Program
A data type tells C what kind of value a variable will store. Let us see each of the four basic types running on its own.
| Data type | Stores | Size (approx) | Example |
|---|---|---|---|
| int | Whole numbers (integers) | 2 or 4 bytes | int age = 20; |
| float | Numbers with decimal points | 4 bytes | float pi = 3.14; |
| double | Decimal numbers with more precision | 8 bytes | double price = 99.99; |
| char | One single character | 1 byte | char grade = 'A'; |
In simple words: the data type tells the machine how to treat your value — int for whole numbers, float/double for decimals, char for one single letter.
Program 1: int (whole numbers)
Example02
Program 2: float (decimal numbers)
Example03
Program 3: double (more precision)
Example04
Program 4: char (one character)
Trainer's Note: Size trick: char is always 1 byte (holds one character). int is the standard whole number. Use float for simple decimals and double when you need very accurate decimals (like scientific calculations).
Example05
Declaration and Initialization
Declaration tells C the type and name. Initialization gives a value at the time of declaration.
Example06
Program: declaration styles in action
Example07
📝 Key Takeaways
- Tokens = keywords, identifiers, constants, operators, special symbols.
- Constants never change; variables can hold different values.
- Identifier rules: start with letter/underscore, no spaces/symbols, no keywords.
- Basic data types: int, float, double, char — each with its own example program.
- Declaration = type + name; initialization = giving a value.
- sizeof tells the memory size of a type.
🧠 Test Your Knowledge
2 QuestionsProgress: 0 / 2