SlideShare a Scribd company logo
An operator is a symbol that tells the compiler to perform specific
mathematical or logical functions. C language is rich in built-in
operators and provides the following types of operators −
 Arithmetic Operators
 Relational Operators
 Logical Operators
 Bitwise Operators
 Assignment Operators
 Misc Operators
C - Operators
Arithmetic Operators
Operator Description Example
+ Adds two operands. A + B = 30
− Subtracts second operand from the
first.
A − B = -10
* Multiplies both operands. A * B = 200
/ Divides numerator by de-numerator. B / A = 2
% Modulus Operator and remainder of
after an integer division.
B % A = 0
++ Increment operator increases the
integer value by one.
A++ = 11
-- Decrement operator decreases the
integer value by one.
A-- = 9
Relational Operators
Operator Description Example
== Checks if the values of two operands are equal or
not. If yes, then the condition becomes true.
(A == B) is not true.
!= Checks if the values of two operands are equal or
not. If the values are not equal, then the condition
becomes true.
(A != B) is true.
> Checks if the value of left operand is greater than the
value of right operand. If yes, then the condition
becomes true.
(A > B) is not true.
< Checks if the value of left operand is less than the
value of right operand. If yes, then the condition
becomes true.
(A < B) is true.
>= Checks if the value of left operand is greater than or
equal to the value of right operand. If yes, then the
condition becomes true.
(A >= B) is not true.
<= Checks if the value of left operand is less than or
equal to the value of right operand. If yes, then the
condition becomes true.
(A <= B) is true.
Logical Operators
Operator Description Example
&& Called Logical AND operator. If both the
operands are non-zero, then the condition
becomes true.
(A && B) is false.
|| Called Logical OR Operator. If any of the
two operands is non-zero, then the
condition becomes true.
(A || B) is true.
! Called Logical NOT Operator. It is used to
reverse the logical state of its operand. If a
condition is true, then Logical NOT
operator will make it false.
!(A && B) is true.
Bitwise Operators
p q p & q p | q p ^ q
0 0 0 0 0
0 1 0 1 1
1 1 1 1 0
1 0 0 1 1
Operator Description Example
& Binary AND Operator copies a bit to the
result if it exists in both operands.
(A & B) = 12, i.e., 0000
1100
| Binary OR Operator copies a bit if it exists in
either operand.
(A | B) = 61, i.e., 0011
1101
^ Binary XOR Operator copies the bit if it is set
in one operand but not both.
(A ^ B) = 49, i.e., 0011
0001
~ Binary Ones Complement Operator is unary
and has the effect of 'flipping' bits.
(~A ) = -61, i.e,. 1100
0011 in 2's complement
form.
<< Binary Left Shift Operator. The left operands
value is moved left by the number of bits
specified by the right operand.
A << 2 = 240 i.e., 1111
0000
>> Binary Right Shift Operator. The left
operands value is moved right by the
number of bits specified by the right
operand.
A >> 2 = 15 i.e., 0000
1111
Assignment Operators
Operator Description Example
= Simple assignment operator. Assigns values from right side operands to
left side operand
C = A + B will assign the value of A + B to
C
+= Add AND assignment operator. It adds the right operand to the left
operand and assign the result to the left operand.
C += A is equivalent to C = C + A
-= Subtract AND assignment operator. It subtracts the right operand from
the left operand and assigns the result to the left operand.
C -= A is equivalent to C = C - A
*= Multiply AND assignment operator. It multiplies the right operand with
the left operand and assigns the result to the left operand.
C *= A is equivalent to C = C * A
/= Divide AND assignment operator. It divides the left operand with the
right operand and assigns the result to the left operand.
C /= A is equivalent to C = C / A
%= Modulus AND assignment operator. It takes modulus using two operands
and assigns the result to the left operand.
C %= A is equivalent to C = C % A
<<= Left shift AND assignment operator. C <<= 2 is same as C = C << 2
>>= Right shift AND assignment operator. C >>= 2 is same as C = C >> 2
&= Bitwise AND assignment operator. C &= 2 is same as C = C & 2
^= Bitwise exclusive OR and assignment operator. C ^= 2 is same as C = C ^ 2
|= Bitwise inclusive OR and assignment operator. C |= 2 is same as C = C | 2
Misc Operators ↦ sizeof & ternary
Operator Description Example
sizeof() Returns the size of a variable. sizeof(a), where a is integer, will
return 4.
& Returns the address of a variable. &a; returns the actual address of
the variable.
* Pointer to a variable. *a;
? : Conditional Expression. If Condition is true ? then value X :
otherwise value Y

More Related Content

PPTX
11operator in c#
PPTX
Python operators part2
PDF
Programming C Part 02
PPTX
Logical Operators C/C++ language Programming
PPTX
Operators in c++
DOC
C programming operators
PPTX
Operator 04 (js)
PPTX
Operators and Expression
11operator in c#
Python operators part2
Programming C Part 02
Logical Operators C/C++ language Programming
Operators in c++
C programming operators
Operator 04 (js)
Operators and Expression

What's hot (16)

DOCX
Bit shift operators
PPTX
C operators
PDF
Java basic operators
PDF
Chapter 5 - Operators in C++
PPTX
Operators in C & C++ Language
PPTX
Python operators
PPT
C Sharp Jn (2)
PPT
Operation and expression in c++
PDF
Python : basic operators
PPTX
Operators in Python
PDF
Operators in python
PPTX
Operators in C/C++
PPTX
Python operators
PPTX
Python Training in Bangalore | Python Operators | Learnbay.in
PPT
Operator & Expression in c++
PPTX
Bit shift operators
C operators
Java basic operators
Chapter 5 - Operators in C++
Operators in C & C++ Language
Python operators
C Sharp Jn (2)
Operation and expression in c++
Python : basic operators
Operators in Python
Operators in python
Operators in C/C++
Python operators
Python Training in Bangalore | Python Operators | Learnbay.in
Operator & Expression in c++
Ad

Similar to Session03 operators (20)

PDF
itft-Operators in java
PPTX
Lecture 2 C++ | Variable Scope, Operators in c++
PDF
Constructor and destructors
PDF
Java basic operators
PPTX
Python notes for students to develop and learn
PPTX
Opeartor &amp; expression
PDF
07 ruby operators
PDF
04. Ruby Operators Slides - Ruby Core Teaching
PPTX
PPT ON JAVA AND UNDERSTANDING JAVA'S PRINCIPLES
PPTX
Operators and it's type
PPTX
Computer programming 2 Lesson 7
PPTX
Java unit1 b- Java Operators to Methods
PPT
python operators.ppt
PPTX
btwggggggggggggggggggggggggggggggisop correct (1).pptx
PPTX
C++ revision add on till now
PPTX
C++ revision add on till now
PDF
C# Fundamentals - Basics of OOPS - Part 2
PPT
C++ chapter 2
PDF
C++ notes.pdf BASIC C++ NOTES FOR BEGGINERS
PDF
C++ Expressions Notes
itft-Operators in java
Lecture 2 C++ | Variable Scope, Operators in c++
Constructor and destructors
Java basic operators
Python notes for students to develop and learn
Opeartor &amp; expression
07 ruby operators
04. Ruby Operators Slides - Ruby Core Teaching
PPT ON JAVA AND UNDERSTANDING JAVA'S PRINCIPLES
Operators and it's type
Computer programming 2 Lesson 7
Java unit1 b- Java Operators to Methods
python operators.ppt
btwggggggggggggggggggggggggggggggisop correct (1).pptx
C++ revision add on till now
C++ revision add on till now
C# Fundamentals - Basics of OOPS - Part 2
C++ chapter 2
C++ notes.pdf BASIC C++ NOTES FOR BEGGINERS
C++ Expressions Notes
Ad

More from HarithaRanasinghe (20)

PDF
annual financial report prime lands 2023/2024
PPTX
Asking Scientific Questions biointrractive
PPTX
Session12 pointers
PPTX
Session11 single dimarrays
PPTX
Session09 multi dimarrays
PPTX
Session07 recursion
PPTX
Session06 functions
PPTX
Session05 iteration structure
PPTX
Session04 selection structure_b
PPTX
Session04 selection structure_a
PPT
Session02 c intro
PPT
Session01 basics programming
PPT
Program flow charts
PDF
Sad -sample_paper
PDF
Sad sample paper - mcq answers
PDF
Model questions
PDF
Model paper algorithms and data structures
PDF
Doc 20180208-wa0001
PDF
Doc 20180130-wa0006
annual financial report prime lands 2023/2024
Asking Scientific Questions biointrractive
Session12 pointers
Session11 single dimarrays
Session09 multi dimarrays
Session07 recursion
Session06 functions
Session05 iteration structure
Session04 selection structure_b
Session04 selection structure_a
Session02 c intro
Session01 basics programming
Program flow charts
Sad -sample_paper
Sad sample paper - mcq answers
Model questions
Model paper algorithms and data structures
Doc 20180208-wa0001
Doc 20180130-wa0006

Recently uploaded (20)

PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Enable Enterprise-Ready Security on IBM i Systems.pdf
PDF
Software Development Methodologies in 2025
PDF
BLW VOCATIONAL TRAINING SUMMER INTERNSHIP REPORT
PDF
Top Generative AI Tools for Patent Drafting in 2025.pdf
PDF
Dell Pro 14 Plus: Be better prepared for what’s coming
PDF
REPORT: Heating appliances market in Poland 2024
PDF
Reimagining Insurance: Connected Data for Confident Decisions.pdf
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
GamePlan Trading System Review: Professional Trader's Honest Take
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PPTX
ABU RAUP TUGAS TIK kelas 8 hjhgjhgg.pptx
PDF
NewMind AI Weekly Chronicles - July'25 - Week IV
PDF
agentic-ai-and-the-future-of-autonomous-systems.pdf
PPTX
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
PDF
Building High-Performance Oracle Teams: Strategic Staffing for Database Manag...
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
PDF
How Onsite IT Support Drives Business Efficiency, Security, and Growth.pdf
PDF
Test Bank, Solutions for Java How to Program, An Objects-Natural Approach, 12...
NewMind AI Weekly Chronicles - August'25 Week I
Enable Enterprise-Ready Security on IBM i Systems.pdf
Software Development Methodologies in 2025
BLW VOCATIONAL TRAINING SUMMER INTERNSHIP REPORT
Top Generative AI Tools for Patent Drafting in 2025.pdf
Dell Pro 14 Plus: Be better prepared for what’s coming
REPORT: Heating appliances market in Poland 2024
Reimagining Insurance: Connected Data for Confident Decisions.pdf
Understanding_Digital_Forensics_Presentation.pptx
GamePlan Trading System Review: Professional Trader's Honest Take
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
ABU RAUP TUGAS TIK kelas 8 hjhgjhgg.pptx
NewMind AI Weekly Chronicles - July'25 - Week IV
agentic-ai-and-the-future-of-autonomous-systems.pdf
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
Building High-Performance Oracle Teams: Strategic Staffing for Database Manag...
NewMind AI Monthly Chronicles - July 2025
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
How Onsite IT Support Drives Business Efficiency, Security, and Growth.pdf
Test Bank, Solutions for Java How to Program, An Objects-Natural Approach, 12...

Session03 operators

  • 1. An operator is a symbol that tells the compiler to perform specific mathematical or logical functions. C language is rich in built-in operators and provides the following types of operators −  Arithmetic Operators  Relational Operators  Logical Operators  Bitwise Operators  Assignment Operators  Misc Operators C - Operators
  • 2. Arithmetic Operators Operator Description Example + Adds two operands. A + B = 30 − Subtracts second operand from the first. A − B = -10 * Multiplies both operands. A * B = 200 / Divides numerator by de-numerator. B / A = 2 % Modulus Operator and remainder of after an integer division. B % A = 0 ++ Increment operator increases the integer value by one. A++ = 11 -- Decrement operator decreases the integer value by one. A-- = 9
  • 3. Relational Operators Operator Description Example == Checks if the values of two operands are equal or not. If yes, then the condition becomes true. (A == B) is not true. != Checks if the values of two operands are equal or not. If the values are not equal, then the condition becomes true. (A != B) is true. > Checks if the value of left operand is greater than the value of right operand. If yes, then the condition becomes true. (A > B) is not true. < Checks if the value of left operand is less than the value of right operand. If yes, then the condition becomes true. (A < B) is true. >= Checks if the value of left operand is greater than or equal to the value of right operand. If yes, then the condition becomes true. (A >= B) is not true. <= Checks if the value of left operand is less than or equal to the value of right operand. If yes, then the condition becomes true. (A <= B) is true.
  • 4. Logical Operators Operator Description Example && Called Logical AND operator. If both the operands are non-zero, then the condition becomes true. (A && B) is false. || Called Logical OR Operator. If any of the two operands is non-zero, then the condition becomes true. (A || B) is true. ! Called Logical NOT Operator. It is used to reverse the logical state of its operand. If a condition is true, then Logical NOT operator will make it false. !(A && B) is true.
  • 5. Bitwise Operators p q p & q p | q p ^ q 0 0 0 0 0 0 1 0 1 1 1 1 1 1 0 1 0 0 1 1
  • 6. Operator Description Example & Binary AND Operator copies a bit to the result if it exists in both operands. (A & B) = 12, i.e., 0000 1100 | Binary OR Operator copies a bit if it exists in either operand. (A | B) = 61, i.e., 0011 1101 ^ Binary XOR Operator copies the bit if it is set in one operand but not both. (A ^ B) = 49, i.e., 0011 0001 ~ Binary Ones Complement Operator is unary and has the effect of 'flipping' bits. (~A ) = -61, i.e,. 1100 0011 in 2's complement form. << Binary Left Shift Operator. The left operands value is moved left by the number of bits specified by the right operand. A << 2 = 240 i.e., 1111 0000 >> Binary Right Shift Operator. The left operands value is moved right by the number of bits specified by the right operand. A >> 2 = 15 i.e., 0000 1111
  • 7. Assignment Operators Operator Description Example = Simple assignment operator. Assigns values from right side operands to left side operand C = A + B will assign the value of A + B to C += Add AND assignment operator. It adds the right operand to the left operand and assign the result to the left operand. C += A is equivalent to C = C + A -= Subtract AND assignment operator. It subtracts the right operand from the left operand and assigns the result to the left operand. C -= A is equivalent to C = C - A *= Multiply AND assignment operator. It multiplies the right operand with the left operand and assigns the result to the left operand. C *= A is equivalent to C = C * A /= Divide AND assignment operator. It divides the left operand with the right operand and assigns the result to the left operand. C /= A is equivalent to C = C / A %= Modulus AND assignment operator. It takes modulus using two operands and assigns the result to the left operand. C %= A is equivalent to C = C % A <<= Left shift AND assignment operator. C <<= 2 is same as C = C << 2 >>= Right shift AND assignment operator. C >>= 2 is same as C = C >> 2 &= Bitwise AND assignment operator. C &= 2 is same as C = C & 2 ^= Bitwise exclusive OR and assignment operator. C ^= 2 is same as C = C ^ 2 |= Bitwise inclusive OR and assignment operator. C |= 2 is same as C = C | 2
  • 8. Misc Operators ↦ sizeof & ternary Operator Description Example sizeof() Returns the size of a variable. sizeof(a), where a is integer, will return 4. & Returns the address of a variable. &a; returns the actual address of the variable. * Pointer to a variable. *a; ? : Conditional Expression. If Condition is true ? then value X : otherwise value Y