Computer Science SLO Based Key Point Notes
👉👉👉 Computer Science 12th Class Notes (Main Page)
************************************
Unit 3: Object-Oriented Programming in C++
3.4 Operators in C++:
Operators are the symbols that are used to perform certain operations on data.
3.4.1 Types of Operator in C++:
Assignment Operator
1. Assignment Operator (=)
Assignment operator = is used in assignment statement to assign a value or computational result to a variable.
Syntax:
Variable = expression;
Example:
1. A = 100;
2. C = A + B;
3. X = Y;
1. A = 100;
2. C = A + B;
3. X = Y;
2. Arithmetic Operators
Those operators which are used to perform mathematical operations on numeric data values are called Arithmetic Operators.
3. Arithmetic Assignment Operators
C++ language provides assignment operators that combine assignment operators with arithmetic operators which are used to perform mathematical operations.
Syntax:
variable op= expression;
Where op can be any mathematical operator.
Example:
1. A += 10; is equivalent to A = A + 10;
2. A – = 10; is equivalent to A = A–10;
3. A *= 10; is equivalent to A = A * 10;
4. A /= 10; is equivalent to A = A / 10;
5. A %= 10; is equivalent to A = A % 10;
Where op can be any mathematical operator.
Example:
1. A += 10; is equivalent to A = A + 10;
2. A – = 10; is equivalent to A = A–10;
3. A *= 10; is equivalent to A = A * 10;
4. A /= 10; is equivalent to A = A / 10;
5. A %= 10; is equivalent to A = A % 10;
4(a) Increment Operator
The increment operator is used to increase the value of a variable by 1.Increment operator can be used in two forms:Prefix form: The increment operator is written before the variable i.e. ++y;
4(B) Decrement Operator
The decrement operator is used to decrease the value of a variable by 1.The decrement operator can be used in two forms:
- Prefix form: The decrement operator is written before the variable i.e. --y;
- Postfix form: The decrement operator is written after the variable i.e. y--;
- Prefix form: The decrement operator is written before the variable i.e. --y;
- Postfix form: The decrement operator is written after the variable i.e. y--;
Difference between Prefix & Postfix of increment/decrement operator
- When these operators are used independently, prefix and postfix form work similarly i.e. the result of A++ and ++A is the same.
- But when these operators are used in a larger expression with other operators than they work differently i.e. A = --B and A = B-- are different.
- In prefix form, the statement A = ++B works in the following manner:
– It increments the value of B by 1
– It assigns the value of B to A.
- In postfix form, the statement A = B++ works in the following manner:
– It assigns the value of B to A
– It increments the value by 1.
- When these operators are used independently, prefix and postfix form work similarly i.e. the result of A++ and ++A is the same.
- But when these operators are used in a larger expression with other operators than they work differently i.e. A = --B and A = B-- are different.
- In prefix form, the statement A = ++B works in the following manner:
– It assigns the value of B to A.
- In postfix form, the statement A = B++ works in the following manner:
– It increments the value by 1.
5. Relational Operators:
- The relational operators are used to compare different data values.
- They produce results as TRUE or FALSE.
- They are used to specify the conditions in the program.
- They are also called comparison Operators as they test conditions that are either TRUE or FALSE.
6. Logical Operators
Logical Operators are used to evaluate compound condition i.e. a statement consists of more than one condition. Following are the logical operators used in C language.
Logical Operators are used to evaluate compound condition i.e. a statement consists of more than one condition.
Following are the logical operators used in C language.
1. AND operator (&&):
It is used to evaluate two conditions. It returns TRUE if both conditions are TRUE and returns FALSE if both or any one condition is FALSE.
Examples:
(A < 10) && (B>50)
(Result ==“PASS”) &&(Percentage > 70)
2. OR operator (||):
It is used to evaluate two conditions. It returns TRUE if both or any one condition is TRUE and returns FALSE if both conditions are FALSE.
Examples:
(A < 50) || (B > 50)
Examples:
(A < 50) || (B > 50)
3. NOT operator (!):
It is used to reverse the result of a condition. It returns TRUE if the condition is FALSE and returns FALSE if the condition is TRUE.
Example: !(A == B)
It is used to reverse the result of a condition. It returns TRUE if the condition is FALSE and returns FALSE if the condition is TRUE.
Example:
!(A == B)7. Ternary Operator
- It is used to return one of two values depending on the result of a condition.
- It is also known as a conditional operator.
- The condition operator has a general form:
(condition)? Expression 1: Expression 2;
- Condition evaluates to either true or false
- If it is true the entire conditional expression takes on the value of expression1.
- If it is false the entire conditional expression takes on the value of expression2.
Example:
#include <iostream.h>
#include <conion.h>
void main()
{
clrscr();
int x,y,k;
x=15;
y=10;
k= (x>y)? x+y: x-y;
cout<<“the value of k is “<<k;
getch();
}
- It is used to return one of two values depending on the result of a condition.
- It is also known as a conditional operator.
- The condition operator has a general form:
- Condition evaluates to either true or false
- If it is true the entire conditional expression takes on the value of expression1.
- If it is false the entire conditional expression takes on the value of expression2.
Example:
#include <iostream.h>
#include <conion.h>
void main()
{
clrscr();
int x,y,k;
x=15;
y=10;
k= (x>y)? x+y: x-y;
cout<<“the value of k is “<<k;
getch();
}
👇👇👇👇👇👇👇👇👇👇👇👇
************************************👉👉👉 Computer Science 12th Class Notes (Main Page)
************************************
(National Book Foundation - As Federal Textbook Board, Islamabad Based on National Curriculum Pakistan 2026-2027 and Onward prescribed by Federal Board of Intermediate and Secondary Education, Islamabad, and All Pakistan Boards)
(National Book Foundation - As Federal Textbook Board, Islamabad
Based on National Curriculum Pakistan 2026-2027 and Onward prescribed by Federal Board of Intermediate and Secondary Education, Islamabad, and All Pakistan Boards)
{Contact WhatsApp # +923339719149 for Class-XII Computer Science Complete SLO-Based Key Points notes in pdf format as well as in PowerPoint Presentation for preparing/delivering the Lectures}
Note: Write me in the comments box below for any query and also Share this information with your class-fellows and friends.
0 Comments
Note: Write me in the comments box below for any queries and also Share this information with your class-fellows and friends.