OPERATORS IN C++ TRB CSI › Programming with C++ › operators

OPERATORS IN C++

Operator என்பது variables அல்லது values மீது ஒரு குறிப்பிட்ட operation செய்ய பயன்படுத்தப்படும் symbol. Simple definition: An operator is a symbol that performs an operation on one or more operands.

Premium — locked Advanced 27 min 252 cards 40 programs 14 MCQs v2
This is a premium lesson. You can see the shape of every card — unlock to read them. Unlock

OPERATORS IN C++…

Premium This card is part of the premium lesson. Unlock
Definition

Operator என்பது variables அல்லது values மீது ஒரு குறிப்பிட்ட operation செய்ய ……

Premium This card is part of the premium lesson. Unlock
Explanation
Example

int c = a + b; இதில்: a , b →……

Premium This card is part of the premium lesson. Unlock
List

- → Operator…

Premium This card is part of the premium lesson. Unlock
List

- operator இரண்டு values-ஐ ad……

Premium This card is part of the premium lesson. Unlock
Simple Explanation

Mathematics-ல்: 10 + 20 இதில்……

Premium This card is part of the premium lesson. Unlock
Simple Explanation

- → Addition operation…

Premium This card is part of the premium lesson. Unlock
Simple Explanation

C++-லும் இதே concept. int result = 10 + 20; இங்கு: 10……

Premium This card is part of the premium lesson. Unlock
Explanation
Operand என்றால் என்ன?

Operator எந்த values மீது வேலை செய்……

Premium This card is part of the premium lesson. Unlock
List

- → Operator…

Premium This card is part of the premium lesson. Unlock
Explanation

Another: x++; இதில்: x → Oper……

Premium This card is part of the premium lesson. Unlock
Flow

Operands ↓ Operator applied ↓……

Premium This card is part of the premium lesson. Unlock
Explanation
Example

10 + 5 ↓ Addition ↓ 15…

Premium This card is part of the premium lesson. Unlock
Explanation
Main types of operators in c++

C++-ல் முக்கியமாக: Arithmetic Operators Relational Operators Logical Operators ……

Premium This card is part of the premium lesson. Unlock

ARITHMETIC OPERATORS

Explanation

Arithmetic calculations செய்ய……

Premium This card is part of the premium lesson. Unlock
Explanation
Addition +

int a = 10; int b = 20; int c……

Premium This card is part of the premium lesson. Unlock
Explanation
Subtraction

int a = 20; int b = 5; int c ……

Premium This card is part of the premium lesson. Unlock
Output
Result
Explanation
Multiplication *

int a = 5; int b = 4; int c =……

Premium This card is part of the premium lesson. Unlock
Output
Result
Explanation
Division /

int a = 20; int b = 5; int c ……

Premium This card is part of the premium lesson. Unlock
Output
Result
Important
Very important - integer division

int x = 5 / 2; Mathematics: 5 / 2 = 2.5 ஆனால் C++ integ……

Premium This card is part of the premium lesson. Unlock
Explanation
Floating division

double x = 5.0 / 2.0;…

Premium This card is part of the premium lesson. Unlock
Output
Result

Also: double x = 5 / 2.0;…

Premium This card is part of the premium lesson. Unlock
Output
Result

ஏனெனில் one operand floating-……

Premium This card is part of the premium lesson. Unlock
Explanation
Modulus %

% remainder கண்டுபிடிக்க பயன்……

Premium This card is part of the premium lesson. Unlock
Program
So
Real Life Example
Modulus examples

10 % 2 = 0 11 % 2 = 1 15 % 4 ……

Premium This card is part of the premium lesson. Unlock
Explanation
Modulus use - even / odd

if (number % 2 == 0) { cout…

Premium This card is part of the premium lesson. Unlock
Important

% normally integer operands-க……

Premium This card is part of the premium lesson. Unlock
Explanation
Example

10 % 3 Valid. Floating-point remainder தேவை……

Premium This card is part of the premium lesson. Unlock
Program
Arithmetic program
Explanation

return 0; }…

Premium This card is part of the premium lesson. Unlock

Notice: 20 / 6 = 3 because in……

Premium This card is part of the premium lesson. Unlock

RELATIONAL OPERATORS

Two values-ஐ compare செய்ய பய……

Premium This card is part of the premium lesson. Unlock
Output
Result
Table
Main relational operators
Explanation
Equal to ==

10 == 10…

Premium This card is part of the premium lesson. Unlock
Output
Result
Output
Result

= → Assignment.…

Premium This card is part of the premium lesson. Unlock
Definition
Meaning

10 value-ஐ x-க்கு assign செய்……

Premium This card is part of the premium lesson. Unlock
Definition
Meaning

x value 10-க்கு equal-ஆ என்று……

Premium This card is part of the premium lesson. Unlock
Explanation
Not equal !=

10 != 20…

Premium This card is part of the premium lesson. Unlock
Output
Result

Because 10 and 20 are not equ……

Premium This card is part of the premium lesson. Unlock
Explanation
Greater than >

20 > 10…

Premium This card is part of the premium lesson. Unlock
Output
Result
Explanation
Less than <

5 < 10…

Premium This card is part of the premium lesson. Unlock
Output
Result
Explanation
Greater than or equal >=

10 >= 10 True. 15 >= 10 True.…

Premium This card is part of the premium lesson. Unlock
Explanation
Less than or equal <=

10…

Premium This card is part of the premium lesson. Unlock
Explanation

return 0; }…

Premium This card is part of the premium lesson. Unlock

Because default C++ output: t……

Premium This card is part of the premium lesson. Unlock
Explanation
Boolalpha

If we want: true false instea……

Premium This card is part of the premium lesson. Unlock
Program
Example

LOGICAL OPERATORS

Multiple conditions combine செ……

Premium This card is part of the premium lesson. Unlock

` ! Logical NOT…

Premium This card is part of the premium lesson. Unlock
Explanation
Logical and &&

Both conditions true என்றால் மட்டும் result true. true && true → ……

Premium This card is part of the premium lesson. Unlock
Explanation

Both conditions: age >= 18 → ……

Premium This card is part of the premium lesson. Unlock
Explanation
Logical or ||

At least one condition true இருந்தால் result true. Truth t……

Premium This card is part of the premium lesson. Unlock
Program
Example
Explanation
Logical not !

Result reverse செய்யும். !tru……

Premium This card is part of the premium lesson. Unlock
Output
Result

Because: !false = true…

Premium This card is part of the premium lesson. Unlock
Table
Truth table
Table
NOT:
Explanation
Short-circuit evaluation

இந்த concept exam/interview-க்கு important. For: A && B A……

Premium This card is part of the premium lesson. Unlock
Program
Example
Program
If
Explanation

First condition: x != 0 → false அதனால் second c……

Premium This card is part of the premium lesson. Unlock
Explanation
Or short circuit

A || B A true என்றால் entire ……

Premium This card is part of the premium lesson. Unlock

ASSIGNMENT OPERATORS

Explanation

Variable-க்கு value assign செய்ய பய……

Premium This card is part of the premium lesson. Unlock
Table
Compound assignment operators
Explanation

[+=] int x = 10; x += 5; Means: x = x + 5; Calcula……

Premium This card is part of the premium lesson. Unlock
Output
Result

x *= 4; Means:…

Premium This card is part of the premium lesson. Unlock
Output
Result

x %= 3; Means:…

Premium This card is part of the premium lesson. Unlock
Explanation

return 0; }…

Premium This card is part of the premium lesson. Unlock

INCREMENT AND DECREMENT OPERATORS

Increment: ++ Decrement: --…

Premium This card is part of the premium lesson. Unlock
Explanation
Increment ++

Value by 1 increase செய்கிறது. int……

Premium This card is part of the premium lesson. Unlock
Explanation
Decrement

Value by 1 decrease செய்கிறது……

Premium This card is part of the premium lesson. Unlock
Explanation
Two types

Increment: ++x → Pre-increment x++ → Pos……

Premium This card is part of the premium lesson. Unlock
Explanation
Pre-increment

int x = 5; int y = ++x; Step-by-step: x ……

Premium This card is part of the premium lesson. Unlock
Explanation
Post-increment

int x = 5; int y = x++; Step-by-step: x = 5 First old……

Premium This card is part of the premium lesson. Unlock
Explanation
Example

int x = 5;…

Premium This card is part of the premium lesson. Unlock

But: int x = 5;…

Premium This card is part of the premium lesson. Unlock
Program
After statement
Explanation
Pre-decrement

int x = 5; int y = --x;…

Premium This card is part of the premium lesson. Unlock
Output
Result
Explanation
Post-decrement

int x = 5; int y = x--;…

Premium This card is part of the premium lesson. Unlock
Output
Result

BITWISE OPERATORS

Bit-level operations செய்ய பயன்படும். Int……

Premium This card is part of the premium lesson. Unlock
Explanation
Example

5 = 0101 3 = 0011 Apply: 0101……

Premium This card is part of the premium lesson. Unlock

0001 So: 5 & 3…

Premium This card is part of the premium lesson. Unlock
Output
Result
Explanation
Bitwise or |

0101 0011…

Premium This card is part of the premium lesson. Unlock

0111…

Premium This card is part of the premium lesson. Unlock
Output
Result

So: 5 | 3 = 7.…

Premium This card is part of the premium lesson. Unlock
Explanation
Bitwise xor ^

XOR: Same bits → 0 Different bits → 1 5 = 0……

Premium This card is part of the premium lesson. Unlock
Output
Result
Explanation
Bitwise not ~

All bits invert செய்கிறது. 0 → 1 1 → 0 Example conceptually: 00000101 ↓ 11111010 ……

Premium This card is part of the premium lesson. Unlock
Explanation
Left shift <<

Bits left side shift செய்கிறத……

Premium This card is part of the premium lesson. Unlock
Output
Result

For non-negative integers, shifting right by one often behaves like division……

Premium This card is part of the premium lesson. Unlock
Explanation
Example

true && false Logical. But: 5……

Premium This card is part of the premium lesson. Unlock

CONDITIONAL / TERNARY OPERATOR

Explanation

C++-ல் ternary operator: ? : இதற்கு three operands இருப்பதால் ternary operator என்று அழைக்க……

Premium This card is part of the premium lesson. Unlock
Output
Result
Flow
Ternary flow

Condition | +---- true ----> Expression 1 | +---- false ---> Expression 2 [IF-ELSE v……

Premium This card is part of the premium lesson. Unlock
Explanation

int maxValue = (a > b) ? a : ……

Premium This card is part of the premium lesson. Unlock
Explanation

return 0; }…

Premium This card is part of the premium lesson. Unlock

SPECIAL OPERATORS

C++-ல் பல special operators உள்ளன. Important ones: sizeof & * :……

Premium This card is part of the premium lesson. Unlock

Common output: 4 But actual s……

Premium This card is part of the premium lesson. Unlock
Explanation
Example

int x = 10;…

Premium This card is part of the premium lesson. Unlock
Explanation
Address-of operator &

Variable-ன் memory address ob……

Premium This card is part of the premium lesson. Unlock
Explanation
Dereference operator *

Pointer points செய்யும் address-ல் ……

Premium This card is part of the premium lesson. Unlock

Here * has a different meanin……

Premium This card is part of the premium lesson. Unlock
Explanation
Example

std::cout Here: :: Scope resolution operator. It……

Premium This card is part of the premium lesson. Unlock
Explanation
Member access .

Object member access செய்ய: s……

Premium This card is part of the premium lesson. Unlock
Explanation
Arrow operator ->

Pointer-to-object மூலம் member access செய்ய: ptr->mark [……

Premium This card is part of the premium lesson. Unlock
Explanation
Function call operator ()

display(); () function call s……

Premium This card is part of the premium lesson. Unlock
Explanation
Comma operator ,

Comma பல contexts-ல் separator ஆகவும், expression operator ஆகவும் இருக்கும். Example separator: int a, b, c; ……

Premium This card is part of the premium lesson. Unlock
Explanation
Operators based on number of operands

Operators-ஐ operands count அடிப்படையிலும் classify செய்யலாம். Unary Operator One operand. Examples: ++x --x !……

Premium This card is part of the premium lesson. Unlock
Output
Result

Here - unary operator. But: a - b Here - bi……

Premium This card is part of the premium lesson. Unlock
Explanation
Operator precedence

When multiple operators occur in one expression, compiler எந்த operation first perform செய்ய வேண்டும் என்பதை ……

Premium This card is part of the premium lesson. Unlock
Explanation
With parentheses

int x = (2 + 3) * 4; Parenthe……

Premium This card is part of the premium lesson. Unlock
Output
Result
Explanation
Common precedence order

For basic exams, remember rou……

Premium This card is part of the premium lesson. Unlock
Explanation

- / %…

Premium This card is part of the premium lesson. Unlock
Explanation

↓…

Premium This card is part of the premium lesson. Unlock
Explanation

- -…

Premium This card is part of the premium lesson. Unlock
Explanation

↓ < >= ↓ == != ↓ && ↓ || ↓ ?: ↓ = += -= *= /……

Premium This card is part of the premium lesson. Unlock
Explanation
Associativity

Same precedence operators multiple times இருந்……

Premium This card is part of the premium lesson. Unlock
List

- is left-associative.…

Premium This card is part of the premium lesson. Unlock
Explanation

So: (20 - 10) - 5 = 10 - 5 = ……

Premium This card is part of the premium lesson. Unlock
Explanation
Right-to-left assignment

Assignment operators associat……

Premium This card is part of the premium lesson. Unlock
Program
Example
Program
Process
Explanation

then…

Premium This card is part of the premium lesson. Unlock
Program
Final
Program
Program - multiple operators
Explanation

int result = a + b * 2;…

Premium This card is part of the premium lesson. Unlock
Explanation

return 0; }…

Premium This card is part of the premium lesson. Unlock
Common Mistake
Common error 2 - integer division

double x = 5 / 2; You might expect: 2.5 But 5 / 2 happens……

Premium This card is part of the premium lesson. Unlock
Output
Result
Common Mistake
Common error 3 - modulus

Do not treat: 10 % 3 as percentage. % means remainder, ……

Premium This card is part of the premium lesson. Unlock
Output
Result
Common Mistake
Common error 4 - pre/post increment

int x = 5; cout…

Premium This card is part of the premium lesson. Unlock

But x after statement: 6 Wher……

Premium This card is part of the premium lesson. Unlock

[COMMON_ERROR 5 - && vs &] condition1 && condition2 Logical AND. n……

Premium This card is part of the premium lesson. Unlock
Dry Run
Dry run 2
Important

Remember these strongly: = → Assignment == → Equality comparison && → L……

Premium This card is part of the premium lesson. Unlock
Memory Trick

Main operator types: A R L A I B C A → Arithmetic R → Rel……

Premium This card is part of the premium lesson. Unlock
TRB Point

What is an operator? An operator is a symbol that ……

Premium This card is part of the premium lesson. Unlock
TRB Point
Trb point - very important

Consider: int x = 10 + 5; Token analysis: int……

Premium This card is part of the premium lesson. Unlock
TRB Point

- → Arithmetic operator…

Premium This card is part of the premium lesson. Unlock
TRB Point

5 → Integer literal ; → Punct……

Premium This card is part of the premium lesson. Unlock
TRB Point
Trb point - pre/post

Given: int x = 5; int y = x++; Final:……

Premium This card is part of the premium lesson. Unlock
Interview Point

Difference between = and ==? ……

Premium This card is part of the premium lesson. Unlock
Program
Example
Explanation

Assigns. x == 10 Compares.…

Premium This card is part of the premium lesson. Unlock
Interview Point

Difference between && and &? && Logical AND Used mainly with Boolean conditions Supports short-circuit ……

Premium This card is part of the premium lesson. Unlock
Interview Point

Difference between x++ and ++x? When used as a standalone statement……

Premium This card is part of the premium lesson. Unlock
MCQ

Which is an arithmetic operat……

Premium This card is part of the premium lesson. Unlock
MCQ

Which operator finds remainde……

Premium This card is part of the premium lesson. Unlock
MCQ

What is 10 % 3?…

Premium This card is part of the premium lesson. Unlock
MCQ

Equality operator is:…

Premium This card is part of the premium lesson. Unlock
MCQ

Assignment operator is:…

Premium This card is part of the premium lesson. Unlock
MCQ

Logical AND operator is:…

Premium This card is part of the premium lesson. Unlock
MCQ

Logical OR operator is:…

Premium This card is part of the premium lesson. Unlock
MCQ

Logical NOT operator is:…

Premium This card is part of the premium lesson. Unlock
MCQ

What is the output? int x = 5……

Premium This card is part of the premium lesson. Unlock
MCQ

Afterward x = 6. 1. What is t……

Premium This card is part of the premium lesson. Unlock
MCQ

What is: 5 / 2 when both oper……

Premium This card is part of the premium lesson. Unlock
MCQ

Which is a ternary operator?…

Premium This card is part of the premium lesson. Unlock
MCQ

x += 5 means:…

Premium This card is part of the premium lesson. Unlock
Output
Result

Answer: 1…

Premium This card is part of the premium lesson. Unlock
Algorithm

1. Which has higher precedenc……

Premium This card is part of the premium lesson. Unlock

Answer: B) * Therefore: 2 + 3……

Premium This card is part of the premium lesson. Unlock
Output
Result
Practice

Find the output: int a = 10; ……

Premium This card is part of the premium lesson. Unlock
Practice
Practice 2

Find final values: int x = 10……

Premium This card is part of the premium lesson. Unlock
Dry Run

x = 10 x += 5 x = 15 x *= 2 x……

Premium This card is part of the premium lesson. Unlock
Practice
Practice 3

Find output: int x = 5; cout…

Premium This card is part of the premium lesson. Unlock
Summary

Operator Operator என்பது operands மீது operation செய்யும் symbol. Main categories: O……

Premium This card is part of the premium lesson. Unlock
Summary

- → Addition - → Subtraction ……

Premium This card is part of the premium lesson. Unlock
Summary

/ → Division % → Remainder = → Assignment == → Comparison && → AND || → OR ! →……

Premium This card is part of the premium lesson. Unlock
Text size
17px
Theme
Contents
Print / PDF
Program