C language chapter 2

🟩 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

TypeKeywordSizeExample
Integerint2 or 4 bytes10
Floating pointfloat4 bytes3.14
Doubledouble8 bytes10.345
Characterchar1 byte‘A’
Voidvoid——

🔹 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;

Leave a Comment

Your email address will not be published. Required fields are marked *