Lesson Plan: Operators and Expressions
Duration: 55 minutes
Subject: Programming In C
Lesson Objectives:
By the end of this lesson, students will be able to:
1. Define operators and expressions in programming.
2. Identify different types of operators.
3. Write and evaluate expressions using various operators.
4. Understand the precedence and associativity of operators.
Lesson Structure:
1. Introduction (10 minutes)
Definition of Operators and Expressions
o Operators: Symbols that perform operations on variables and values.
o Expressions: Combinations of variables, values, and operators that produce a
result.
o Example: a = 5 + 3; (Here, + is an operator, and 5 + 3 is an expression).
Real-life analogy: Explain operators using mathematical operations (addition,
subtraction).
Reference:
"Python Crash Course" by Eric Matthes
"C Programming Language" by Brian Kernighan & Dennis Ritchie
2. Types of Operators (15 minutes)
a. Arithmetic Operators (Addition, Subtraction, Multiplication, Division, Modulus,
Exponentiation)
Example: x = 10 + 5;
b. Relational (Comparison) Operators (==, !=, >, <, >=, <=)
Example: 5 > 3 → True
c. Logical Operators (AND, OR, NOT)
Example: (x > 3) && (x < 10);
d. Assignment Operators (=, +=, -=, *=, /=, %=)
Example: x += 2; (Equivalent to x = x + 2;)
e. Bitwise Operators (&, |, ^, ~, <<, >>)
Example: 5 & 3 (Performs bitwise AND operation)
f. Ternary Operator (condition ? expr1 : expr2;)
Example: result = (x > y) ? x : y;
Reference:
"Programming in ANSI C" by E. Balagurusamy
Geeks for Geeks - Operators in C
3. Operator Precedence and Associativity (10 minutes)
Precedence: Defines which operator is executed first.
o Example: x = 5 + 3 * 2; (Multiplication is done first)
Associativity: Defines how operators of the same precedence are executed (Left to Right
or Right to Left).
Example Table:
Operator Associativity
* / % Left to Right
+ - Left to Right
= Right to Left
Reference:
"Introduction to the Theory of Computation" by Michael Sipser
4. Hands-on Coding Activity (15 minutes)
Exercise 1: Write a program using arithmetic operators to calculate the area of a
rectangle.
#include <stdio.h>
int main() {
int length = 10, width = 5;
int area = length * width;
printf("Area of Rectangle: %d", area);
return 0;
}
Exercise 2: Demonstrate logical and comparison operators in an if condition.
#include <stdio.h>
int main() {
int x = 10, y = 20;
if (x < y && y > 15) {
printf("Condition is True");
}
return 0;
}
Discussion: Ask students to modify and test expressions.
Conclusion & Recap (5 minutes)
Quick recap of key points.
Ask students to explain operator precedence with an example.
Assign homework: Solve operator-based questions from reference books.
Reference:
"Let Us C" by Yashavant Kanetkar
TutorialsPoint - Operators in C