🟩 Chapter 2: Data Types, Variables, and Operators
🔹 1. Tokens in C
Basic building blocks:
- Keywords – reserved words (e.g.,Â
int,Âif,Âelse,Âreturn) - Identifiers – names of variables, functions, etc.
- Constants – fixed values (e.g.,Â
10,Â'A',Â3.14) - Operators – symbols that perform operations
- Separators –Â
(),Â{},Â[],Â;,Â,
🔹 2. Data Types in C
| Type | Keyword | Size | Example |
|---|---|---|---|
| Integer | int | 2 or 4 bytes | 10 |
| Floating point | float | 4 bytes | 3.14 |
| Double | double | 8 bytes | 10.345 |
| Character | char | 1 byte | ‘A’ |
| Void | void | — | — |
🔹 3. Variables
Used to store data temporarily.
Syntax:
int age = 20;
Rules:
- Must start with a letter or underscore
- No spaces
- Case-sensitive (
Age ≠age)
🔹 4. Constants
Values that do not change during execution.
const float PI = 3.14;
🔹 5. Operators
A. Arithmetic Operators
+, -, *, /, %
B. Relational Operators
==, !=, >, <, >=, <=
C. Logical Operators
&&, ||, !
D. Assignment Operators
=, +=, -=, *=, /=, %=
E. Increment/Decrement
++, --
F. Conditional (Ternary)
(condition) ? expression1 : expression2;
G. Bitwise Operators
&, |, ^, ~, <<, >>
🔹 6. Type Conversion
- Implicit (Automatic) – smaller → larger type
- Explicit (Casting) – manual conversion
float a = (float)5 / 2;
