SlideShare a Scribd company logo
1 of 42
Operators In
C & C++ Programming Language
Contents:
 Operator
 Arithmetic Operator
 Relational Operator
 Bitwise Operator
 Assignment Operator
 Misc. Operator
Operator
 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
Arithmetic Operator
 + (Addition) Operator
 - (Subtraction) Operator
 * (Multiplication) Operator
 / (Division) Operator
 % (Modular) Operator
 ++ (Increment) Operator
 -- (Decrement) Operator
Arithmetic Operator
 + (Addition) Operator: It is a Binary Operator. It return the sum of two
operands without effecting the value of any operand.
 Let us consider a = 2 & b = 5.
 If we write a + b then, it will return 7.
 If we write 10 + 2 then, it will return 12.
Arithmetic Operator
 - (Subtraction) Operator: It is a Binary Operator. It return the subtraction of
two operands without effecting the value of any operand.
 Let us consider a = 2 & b = 5.
 If we write a - b then, it will return -3.
 If we write 10 - 2 then, it will return 8.
Arithmetic Operator
 * (Multiplication) Operator: It is a Binary Operator. It return the product of
two operands without effecting the value of any operand.
 Let us consider a = 2 & b = 5.
 If we write a * b then, it will return 10.
 If we write 10 * 2 then, it will return 20.
Arithmetic Operator
 / (Division) Operator: It is a Binary Operator. It return the quotient by dividing
left operand with right operand without effecting the value of any operand.
 Let us consider a = 2 & b = 5.
 If we write a / b then, it will return 0.
 If we write 10 / 2 then, it will return 5.
Arithmetic Operator
 % (Modulus) Operator: It is a Binary Operator. It return the remainder after
dividing left operand by right operand without effecting the value of any
operand.
 Let us consider a = 2 & b = 5.
 If we write a % b then, it will return 2.
 If we write 10 % 2 then, it will return 0.
Arithmetic Operator
 ++ Increment Operator: It is a Unary Operator. It increase the value of
operand used with this operator by 1 and assigned the new updated value in
the operand and return the value according to its notation (prefix/postfix).
 Let us consider a = 4. Then,
 Using prefix notation:
b = ++a,
value of a & b will be respectively 5 & 5.
 Using postfix notation:
b = a++,
value of a & b will be respectively 5 & 4.
Arithmetic Operator
 -- Decrement Operator: It is a Unary Operator. It decrease the value of
operand used with this operator by 1 and assigned the new updated value in
the operand and return the value according to its notation (prefix/postfix).
 Let us consider a = 4. Then,
 Using prefix notation:
b = --a,
value of a & b will be respectively 3 & 3.
 Using postfix notation:
b = a--,
value of a & b will be respectively 3 & 4.
Relational Operator
 == (is Equals to?) Operator
 != (is Not Equals to?) Operator
 < (is Less Than?) Operator
 > (is Greater Than?) Operator
 <= (is Less Than or Equals to?) Operator
 >= (is Greater Than or Equals to?) Operator
Relational Operator
 == (is Equals to?) Operator: It is Binary Operator. It compare the value of two
operand and check whether they are equal or not, without effecting the value
of any operand. If they are equal then it returns true else, it returns false.
 Let us consider a = 5, b = 6
 If we write (a == b) then, it returns false.
 If we write (5 == 5) then, it returns true.
 If we write (3 == 2) then, it returns false.
Relational Operator
 != (is Not Equals to?) Operator: It is Binary Operator. It compare the value of
two operand and check whether they are equal or not, without effecting the
value of any operand. If they are equal then it returns false else, it returns
false.
 Let us consider a = 5, b = 6
 If we write (a != b) then, it returns true.
 If we write (5 != 5) then, it returns false.
 If we write (3 != 2) then, it returns true.
Relational Operator
 < (is Less Than?) Operator: It is Binary Operator. It compare the value or two
operand and check whether left operand is smaller than right operand or not,
without effecting the value of any operand. If left operand is smaller then, it
returns true else, it returns false.
 Let us consider a = 5, b = 6
 If we write (a < b) then, it returns true.
 If we write (5 < 5) then, it returns false.
 If we write (3 < 2) then, it returns false.
 If we write (2 < 3) then, it returns true.
Relational Operator
 > (is Greater Than?) Operator: It is Binary Operator. It compare the value or
two operand and check whether left operand is greater than right operand or
not, without effecting the value of any operand. If left operand is greater
then, it returns true else, it returns false.
 Let us consider a = 5, b = 6
 If we write (a > b) then, it returns false.
 If we write (5 > 5) then, it returns false.
 If we write (3 > 2) then, it returns true.
 If we write (2 > 3) then, it returns false.
Relational Operator
 <= (is Less Than or Equals to?) Operator: It is Binary Operator. It compare the
value or two operand and check whether left operand is smaller than or
equals to right operand or not, without effecting the value of any operand. If
left operand is smaller or equal then, it returns true else, it returns false.
 Let us consider a = 5, b = 6
 If we write (a < b) then, it returns true.
 If we write (5 < 5) then, it returns true.
 If we write (3 < 2) then, it returns false.
 If we write (2 < 3) then, it returns true.
Relational Operator
 >= (is Greater Than or Equals to?) Operator: It is Binary Operator. It compare
the value or two operand and check whether left operand is greater than or
equals to right operand or not, without effecting the value of any operand. If
left operand is greater or equal then, it returns true else, it returns false.
 Let us consider a = 5, b = 6
 If we write (a < b) then, it returns false.
 If we write (5 < 5) then, it returns true.
 If we write (3 < 2) then, it returns true.
 If we write (2 < 3) then, it returns false.
Bitwise Operator
 Bitwise & (AND) Operator
 Bitwise | (OR) Operator
 Bitwise ^ (XOR) Operator
 Bitwise ~ (One’s Compliment) Operator
 Bitwise << (Left Shift) Operator
 Bitwise >> (Right Shift) Operator
Bitwise Operator
 Bitwise operators work on bits and perform bit by bit operation. All Bitwise
Operators are Binary Operator except ~(One’s Compliment) operator. The
Truth table for bitwise & (AND), | (OR), ^ (XOR) operator is as follow:
 There are two more bitwise operator i.e. >> (Right Shift), << (Left Shift)
Operator.
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
Bitwise Operator
 Binary & (AND) Operator:
 Bitwise & (AND) operator requires two operands to perform AND operation bit by
bit on them.
 Let us consider a = (5)10 = (0101)2, b = (3)10 = (0011)2
 Then c = a & b will be 1 that can be calculated as AND operation perform on a and
b as shown below:
a = 0101
b= 0011
---------
c = 0001
c = (0001)2 = (1)10
Bitwise Operator
 Binary| (OR) Operator:
 Bitwise | (OR) operator requires two operands to perform OR operation bit by bit
on them.
 Let us consider a = (5)10 = (0101)2, b = (3)10 = (0011)2
 Then c = a | b will be 7 that can be calculated as OR operation perform on a and b
as shown below:
a = 0101
b= 0011
---------
c = 0111
c = (0111)2 = (7)10
Bitwise Operator
 Binary ^ (XOR) Operator:
 Bitwise ^ (XOR) operator requires two operands to perform XOR operation bit by
bit on them.
 Let us consider a = (5)10 = (0101)2, b = (3)10 = (0011)2
 Then c = a ^ b will be 6 that can be calculated as OR operation perform on a and b
as shown below:
a = 0101
b= 0011
---------
c = 0110
c = (0111)2 = (6)10
Bitwise Operator
 Binary ~ (One’s Complement) Operator:
 Bitwise ~ (One’s Complement) operator require only a single operands to perform
it’s operation bit by bit or it performs one’s compliment on the operand.
 Let us consider a = (5)10 = (0101)2
 Then b = ~a will be 10 that can be calculated as inverting each bit as shown
below:
a = 0101
----------
b = 1010
b = (0111)2 = (10)10
Bitwise Operator
 Binary << (Left Shift) Operator:
 This operator shift the each bit of the operand to left.
 It requires two operand
 Left operand on which operation is to be performed
 Right operand to specify how many times bits are shifted by 1.
 Let us consider a = (5)10 = (0101)2
 Then b = a << 2 will be 4 that can be calculated as shown below
a = 0101
----------
b = 1010
----------
b = 0100
b = (0100)2 = (4)10
Bitwise Operator
 Binary >> (Right Shift) Operator:
 This operator shift the each bit of the operand to right.
 It requires two operand
 Left operand on which operation is to be performed
 Right operand to specify how many times bits are shifted by 1.
 Let us consider a = (5)10 = (0101)2
 Then b = a >> 2 will be 1 that can be calculated as shown below
a = 0101
----------
b = 0010
----------
b = 0001
b = (0001)2 = (1)10
Assignment Operator
 = (Simple Assignment) Operator
 += (Add AND Assignment) Operator
 -= (Subtract AND Assignment) Operator
 *= (Multiply AND Assignment) operator
 /= (Divide AND Assignment) operator
 %= (Modulus AND Assignment) operator
 <<= (Left Shift AND Assignment) operator
 >>= (Right Shift AND Assignment) operator
 &= (Bitwise AND and Assignment) operator
 |= (Bitwise OR and Assignment) operator
 ^= (Bitwise XOR and Assignment) operator
Assignment Operator
 = (Simple Assignment) operator: This operator assign the value of the
operand or value returned after executing an expression on it’s right to the
operand to it’s left.
 Let us consider a = 5, b = 3, c = 0
 If we write c = a + b, then c will be 8
 And if we write c = a, then c will be 5
Assignment Operator
 += (Add AND Assignment) operator: This operator add the operand on it’s
both sides and assign the result to the operand on it’s left.
 Let us consider a = 5, b = 3, c = 2
 If we write c += a + b, then c will be 10,
 If we write c+= a, then c will be 7,
 And if we write c += 2, then c will be 4.
Assignment Operator
 -= (Subtract AND Assignment) operator: This operator subtract the operand
on it’s right from the left operand and assign the result to the operand on it’s
left.
 Let us consider a = 5, b = 3, c = 9
 If we write c -= a + b, then c will be 1,
 If we write c-= a, then c will be 4,
 And if we write c -= 2, then c will be 7.
Assignment Operator
 *= (Multiply AND Assignment) operator: This operator Multiply the operand
on it’s both sides and assign the result to the operand on it’s left.
 Let us consider a = 5, b = 3, c = 2
 If we write c *= a + b, then c will be 16,
 If we write c*= a, then c will be 10,
 And if we write c *= 3, then c will be 6.
Assignment Operator
 /= (Divide AND Assignment) operator: This operator divide the operand on
the left with the right operand and assign the quotient to the operand on it’s
left.
 Let us consider a = 2, b = 3, c = 10
 If we write c /= a + b, then c will be 2,
 If we write c/= a, then c will be 5,
 And if we write c /= 5, then c will be 2.
Assignment Operator
 %= (Modulus AND Assignment) operator: This operator divide the operand on
the left with the right operand and assign the remainder to the operand on
it’s left.
 Let us consider a = 2, b = 3, c = 10
 If we write c %= a + b, then c will be 0,
 If we write c%= a, then c will be 0,
 And if we write c %= 3, then c will be 1.
Assignment Operator
 <<= (Left Shift AND Assignment) operator: This operator shift bits of the left
operand to left by the value of right operand and assign the result to the
operand on it’s left.
 Let us consider a = 2, b = 1
 If we write a<<=b, then a will be 4,
 If we write b<<=3, then b will be 8.
Assignment Operator
 >>= (Right Shift AND Assignment) operator: This operator shift bits of the
left operand to right by the value of right operand and assign the result to the
operand on it’s left.
 Let us consider a = 2, b = 1
 If we write a>>=b, then a will be 1,
 If we write a>>=2, then b will be 0.
Assignment Operator
 &= (Bitwise AND and Assignment) operator: This operator performs the AND
operation on bits of the left operand with right operand and assign the result
to the operand on it’s left.
 Let us consider a = 5, b = 3
 If we write a&=b, then a will be 1,
 If we write a&=2, then b will be 0.
Assignment Operator
 |= (Bitwise OR and Assignment) operator: This operator performs the OR
operation on bits of the left operand with right operand and assign the result
to the operand on it’s left.
 Let us consider a = 5, b = 3
 If we write a|=b, then a will be 7,
 If we write a|=2, then b will be 7.
Assignment Operator
 ^= (Bitwise XOR and Assignment) operator: This operator performs the XOR
operation on bits of the left operand with right operand and assign the result
to the operand on it’s left.
 Let us consider a = 5, b = 3
 If we write a^=b, then a will be 6,
 If we write a^=2, then b will be 7.
Misc. Operator
 sizeof Operator
 & (referencing) Operator
 * (dereferencing) Operator
 ? : (Turnery Operator)
Misc. Operator
 sizeof Operator: This operator takes operand(variable name/data type keyword)
as parameter and return the memory size consume by the operand in bytes.
 Let us assume a as integer variable
 Then sizeof(a) will return 4 (for 32bit C compilers) or 2(for 16bit C compilers).
 Similarly sizeof(float) will return 4, sizeof(char) will return 1 etc.
Misc. Operator
 & (referencing/address) Operator: It uses only one operand on it’s right and it
returns the memory address of the operand as unsigned integer data type.
 printf(“%u”, &a); will display 6422316(may be different on different machine & every
execution) on the console.
 * (dereferencing) Operator: It is pointer to the variable. This operator used to
declare the pointer variable & extracting the value stored at the address stored in
pointer variable.
 Let us assume a = 10, *b = &a,
 if we write c = *b then c will be 10.
Misc. Operator
 ? : (Conditional) Operator: This operator requires three expressions
 1. Conditional expression
 2. Expression to execute if condition is true
 3. Expression to execute if condition is false
 Syntax: (condition) ? (Expression for true) : (expression for false);
 Let us assume a = 5, b = 1
 If c = (a > b) ? a : b; then value of c will be 5
 If c = (a < b) ? a : b; then value of c will be 1

More Related Content

What's hot

Operators and expressions in C++
Operators and expressions in C++Operators and expressions in C++
Operators and expressions in C++Neeru Mittal
 
Master method theorem
Master method theoremMaster method theorem
Master method theoremRajendran
 
presentation on (Boolean rules & laws)
presentation on (Boolean rules & laws)presentation on (Boolean rules & laws)
presentation on (Boolean rules & laws)kinza arshad
 
simplification of boolean algebra
simplification of boolean algebrasimplification of boolean algebra
simplification of boolean algebramayannpolisticoLNU
 
Data Structure and Algorithms
Data Structure and Algorithms Data Structure and Algorithms
Data Structure and Algorithms ManishPrajapati78
 
Infix to Postfix Conversion Using Stack
Infix to Postfix Conversion Using StackInfix to Postfix Conversion Using Stack
Infix to Postfix Conversion Using StackSoumen Santra
 
Operators and expressions in c language
Operators and expressions in c languageOperators and expressions in c language
Operators and expressions in c languagetanmaymodi4
 
19. Data Structures and Algorithm Complexity
19. Data Structures and Algorithm Complexity19. Data Structures and Algorithm Complexity
19. Data Structures and Algorithm ComplexityIntro C# Book
 
Lecture 04 normalization
Lecture 04 normalization Lecture 04 normalization
Lecture 04 normalization emailharmeet
 
Conversion of Infix to Prefix and Postfix with Stack
Conversion of Infix to Prefix and Postfix with StackConversion of Infix to Prefix and Postfix with Stack
Conversion of Infix to Prefix and Postfix with Stacksahil kumar
 
Fibonacci search
Fibonacci searchFibonacci search
Fibonacci searchneilluiz94
 
Operators in C Programming
Operators in C ProgrammingOperators in C Programming
Operators in C Programmingprogramming9
 
Boolean expression org.
Boolean expression org.Boolean expression org.
Boolean expression org.mshoaib15
 

What's hot (20)

Operators and expressions in C++
Operators and expressions in C++Operators and expressions in C++
Operators and expressions in C++
 
Master method theorem
Master method theoremMaster method theorem
Master method theorem
 
Relational Calculus
Relational CalculusRelational Calculus
Relational Calculus
 
Control structures
Control structuresControl structures
Control structures
 
Boolean Algebra
Boolean AlgebraBoolean Algebra
Boolean Algebra
 
presentation on (Boolean rules & laws)
presentation on (Boolean rules & laws)presentation on (Boolean rules & laws)
presentation on (Boolean rules & laws)
 
Infix to postfix conversion
Infix to postfix conversionInfix to postfix conversion
Infix to postfix conversion
 
simplification of boolean algebra
simplification of boolean algebrasimplification of boolean algebra
simplification of boolean algebra
 
Binary search tree(bst)
Binary search tree(bst)Binary search tree(bst)
Binary search tree(bst)
 
Data Structure and Algorithms
Data Structure and Algorithms Data Structure and Algorithms
Data Structure and Algorithms
 
Operators
OperatorsOperators
Operators
 
Infix to Postfix Conversion Using Stack
Infix to Postfix Conversion Using StackInfix to Postfix Conversion Using Stack
Infix to Postfix Conversion Using Stack
 
Operators and expressions in c language
Operators and expressions in c languageOperators and expressions in c language
Operators and expressions in c language
 
19. Data Structures and Algorithm Complexity
19. Data Structures and Algorithm Complexity19. Data Structures and Algorithm Complexity
19. Data Structures and Algorithm Complexity
 
sorting and its types
sorting and its typessorting and its types
sorting and its types
 
Lecture 04 normalization
Lecture 04 normalization Lecture 04 normalization
Lecture 04 normalization
 
Conversion of Infix to Prefix and Postfix with Stack
Conversion of Infix to Prefix and Postfix with StackConversion of Infix to Prefix and Postfix with Stack
Conversion of Infix to Prefix and Postfix with Stack
 
Fibonacci search
Fibonacci searchFibonacci search
Fibonacci search
 
Operators in C Programming
Operators in C ProgrammingOperators in C Programming
Operators in C Programming
 
Boolean expression org.
Boolean expression org.Boolean expression org.
Boolean expression org.
 

Similar to Operators in C & C++ Language

C++ Expressions Notes
C++ Expressions NotesC++ Expressions Notes
C++ Expressions NotesProf Ansari
 
java operators
 java operators java operators
java operatorsJadavsejal
 
itft-Operators in java
itft-Operators in javaitft-Operators in java
itft-Operators in javaAtul Sehdev
 
11operator in c#
11operator in c#11operator in c#
11operator in c#Sireesh K
 
Operators in Python
Operators in PythonOperators in Python
Operators in PythonAnusuya123
 
Operators
OperatorsOperators
OperatorsKamran
 
C Sharp Jn (2)
C Sharp Jn (2)C Sharp Jn (2)
C Sharp Jn (2)jahanullah
 
Operators expressions-and-statements
Operators expressions-and-statementsOperators expressions-and-statements
Operators expressions-and-statementsCtOlaf
 
Python operators part2
Python operators part2Python operators part2
Python operators part2Vishal Dutt
 
Lecture 2 C++ | Variable Scope, Operators in c++
Lecture 2 C++ | Variable Scope, Operators in c++Lecture 2 C++ | Variable Scope, Operators in c++
Lecture 2 C++ | Variable Scope, Operators in c++Himanshu Kaushik
 
operators and expressions in c++
 operators and expressions in c++ operators and expressions in c++
operators and expressions in c++sanya6900
 
Bit shift operators
Bit shift operatorsBit shift operators
Bit shift operatorsalldesign
 

Similar to Operators in C & C++ Language (20)

Session03 operators
Session03 operatorsSession03 operators
Session03 operators
 
C++ Expressions Notes
C++ Expressions NotesC++ Expressions Notes
C++ Expressions Notes
 
java operators
 java operators java operators
java operators
 
itft-Operators in java
itft-Operators in javaitft-Operators in java
itft-Operators in java
 
11operator in c#
11operator in c#11operator in c#
11operator in c#
 
Operators in Python
Operators in PythonOperators in Python
Operators in Python
 
Operators
OperatorsOperators
Operators
 
C Sharp Jn (2)
C Sharp Jn (2)C Sharp Jn (2)
C Sharp Jn (2)
 
C Sharp Jn (2)
C Sharp Jn (2)C Sharp Jn (2)
C Sharp Jn (2)
 
Operators expressions-and-statements
Operators expressions-and-statementsOperators expressions-and-statements
Operators expressions-and-statements
 
Opeartor &amp; expression
Opeartor &amp; expressionOpeartor &amp; expression
Opeartor &amp; expression
 
Java basic operators
Java basic operatorsJava basic operators
Java basic operators
 
Java basic operators
Java basic operatorsJava basic operators
Java basic operators
 
Python operators part2
Python operators part2Python operators part2
Python operators part2
 
Lecture 2 C++ | Variable Scope, Operators in c++
Lecture 2 C++ | Variable Scope, Operators in c++Lecture 2 C++ | Variable Scope, Operators in c++
Lecture 2 C++ | Variable Scope, Operators in c++
 
Operator 04 (js)
Operator 04 (js)Operator 04 (js)
Operator 04 (js)
 
Operators and it's type
Operators and it's type Operators and it's type
Operators and it's type
 
07 ruby operators
07 ruby operators07 ruby operators
07 ruby operators
 
operators and expressions in c++
 operators and expressions in c++ operators and expressions in c++
operators and expressions in c++
 
Bit shift operators
Bit shift operatorsBit shift operators
Bit shift operators
 

Recently uploaded

How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxChelloAnnAsuncion2
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.arsicmarija21
 
ROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationAadityaSharma884161
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 

Recently uploaded (20)

How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.
 
ROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint Presentation
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 

Operators in C & C++ Language

  • 1. Operators In C & C++ Programming Language
  • 2. Contents:  Operator  Arithmetic Operator  Relational Operator  Bitwise Operator  Assignment Operator  Misc. Operator
  • 3. Operator  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
  • 4. Arithmetic Operator  + (Addition) Operator  - (Subtraction) Operator  * (Multiplication) Operator  / (Division) Operator  % (Modular) Operator  ++ (Increment) Operator  -- (Decrement) Operator
  • 5. Arithmetic Operator  + (Addition) Operator: It is a Binary Operator. It return the sum of two operands without effecting the value of any operand.  Let us consider a = 2 & b = 5.  If we write a + b then, it will return 7.  If we write 10 + 2 then, it will return 12.
  • 6. Arithmetic Operator  - (Subtraction) Operator: It is a Binary Operator. It return the subtraction of two operands without effecting the value of any operand.  Let us consider a = 2 & b = 5.  If we write a - b then, it will return -3.  If we write 10 - 2 then, it will return 8.
  • 7. Arithmetic Operator  * (Multiplication) Operator: It is a Binary Operator. It return the product of two operands without effecting the value of any operand.  Let us consider a = 2 & b = 5.  If we write a * b then, it will return 10.  If we write 10 * 2 then, it will return 20.
  • 8. Arithmetic Operator  / (Division) Operator: It is a Binary Operator. It return the quotient by dividing left operand with right operand without effecting the value of any operand.  Let us consider a = 2 & b = 5.  If we write a / b then, it will return 0.  If we write 10 / 2 then, it will return 5.
  • 9. Arithmetic Operator  % (Modulus) Operator: It is a Binary Operator. It return the remainder after dividing left operand by right operand without effecting the value of any operand.  Let us consider a = 2 & b = 5.  If we write a % b then, it will return 2.  If we write 10 % 2 then, it will return 0.
  • 10. Arithmetic Operator  ++ Increment Operator: It is a Unary Operator. It increase the value of operand used with this operator by 1 and assigned the new updated value in the operand and return the value according to its notation (prefix/postfix).  Let us consider a = 4. Then,  Using prefix notation: b = ++a, value of a & b will be respectively 5 & 5.  Using postfix notation: b = a++, value of a & b will be respectively 5 & 4.
  • 11. Arithmetic Operator  -- Decrement Operator: It is a Unary Operator. It decrease the value of operand used with this operator by 1 and assigned the new updated value in the operand and return the value according to its notation (prefix/postfix).  Let us consider a = 4. Then,  Using prefix notation: b = --a, value of a & b will be respectively 3 & 3.  Using postfix notation: b = a--, value of a & b will be respectively 3 & 4.
  • 12. Relational Operator  == (is Equals to?) Operator  != (is Not Equals to?) Operator  < (is Less Than?) Operator  > (is Greater Than?) Operator  <= (is Less Than or Equals to?) Operator  >= (is Greater Than or Equals to?) Operator
  • 13. Relational Operator  == (is Equals to?) Operator: It is Binary Operator. It compare the value of two operand and check whether they are equal or not, without effecting the value of any operand. If they are equal then it returns true else, it returns false.  Let us consider a = 5, b = 6  If we write (a == b) then, it returns false.  If we write (5 == 5) then, it returns true.  If we write (3 == 2) then, it returns false.
  • 14. Relational Operator  != (is Not Equals to?) Operator: It is Binary Operator. It compare the value of two operand and check whether they are equal or not, without effecting the value of any operand. If they are equal then it returns false else, it returns false.  Let us consider a = 5, b = 6  If we write (a != b) then, it returns true.  If we write (5 != 5) then, it returns false.  If we write (3 != 2) then, it returns true.
  • 15. Relational Operator  < (is Less Than?) Operator: It is Binary Operator. It compare the value or two operand and check whether left operand is smaller than right operand or not, without effecting the value of any operand. If left operand is smaller then, it returns true else, it returns false.  Let us consider a = 5, b = 6  If we write (a < b) then, it returns true.  If we write (5 < 5) then, it returns false.  If we write (3 < 2) then, it returns false.  If we write (2 < 3) then, it returns true.
  • 16. Relational Operator  > (is Greater Than?) Operator: It is Binary Operator. It compare the value or two operand and check whether left operand is greater than right operand or not, without effecting the value of any operand. If left operand is greater then, it returns true else, it returns false.  Let us consider a = 5, b = 6  If we write (a > b) then, it returns false.  If we write (5 > 5) then, it returns false.  If we write (3 > 2) then, it returns true.  If we write (2 > 3) then, it returns false.
  • 17. Relational Operator  <= (is Less Than or Equals to?) Operator: It is Binary Operator. It compare the value or two operand and check whether left operand is smaller than or equals to right operand or not, without effecting the value of any operand. If left operand is smaller or equal then, it returns true else, it returns false.  Let us consider a = 5, b = 6  If we write (a < b) then, it returns true.  If we write (5 < 5) then, it returns true.  If we write (3 < 2) then, it returns false.  If we write (2 < 3) then, it returns true.
  • 18. Relational Operator  >= (is Greater Than or Equals to?) Operator: It is Binary Operator. It compare the value or two operand and check whether left operand is greater than or equals to right operand or not, without effecting the value of any operand. If left operand is greater or equal then, it returns true else, it returns false.  Let us consider a = 5, b = 6  If we write (a < b) then, it returns false.  If we write (5 < 5) then, it returns true.  If we write (3 < 2) then, it returns true.  If we write (2 < 3) then, it returns false.
  • 19. Bitwise Operator  Bitwise & (AND) Operator  Bitwise | (OR) Operator  Bitwise ^ (XOR) Operator  Bitwise ~ (One’s Compliment) Operator  Bitwise << (Left Shift) Operator  Bitwise >> (Right Shift) Operator
  • 20. Bitwise Operator  Bitwise operators work on bits and perform bit by bit operation. All Bitwise Operators are Binary Operator except ~(One’s Compliment) operator. The Truth table for bitwise & (AND), | (OR), ^ (XOR) operator is as follow:  There are two more bitwise operator i.e. >> (Right Shift), << (Left Shift) Operator. 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
  • 21. Bitwise Operator  Binary & (AND) Operator:  Bitwise & (AND) operator requires two operands to perform AND operation bit by bit on them.  Let us consider a = (5)10 = (0101)2, b = (3)10 = (0011)2  Then c = a & b will be 1 that can be calculated as AND operation perform on a and b as shown below: a = 0101 b= 0011 --------- c = 0001 c = (0001)2 = (1)10
  • 22. Bitwise Operator  Binary| (OR) Operator:  Bitwise | (OR) operator requires two operands to perform OR operation bit by bit on them.  Let us consider a = (5)10 = (0101)2, b = (3)10 = (0011)2  Then c = a | b will be 7 that can be calculated as OR operation perform on a and b as shown below: a = 0101 b= 0011 --------- c = 0111 c = (0111)2 = (7)10
  • 23. Bitwise Operator  Binary ^ (XOR) Operator:  Bitwise ^ (XOR) operator requires two operands to perform XOR operation bit by bit on them.  Let us consider a = (5)10 = (0101)2, b = (3)10 = (0011)2  Then c = a ^ b will be 6 that can be calculated as OR operation perform on a and b as shown below: a = 0101 b= 0011 --------- c = 0110 c = (0111)2 = (6)10
  • 24. Bitwise Operator  Binary ~ (One’s Complement) Operator:  Bitwise ~ (One’s Complement) operator require only a single operands to perform it’s operation bit by bit or it performs one’s compliment on the operand.  Let us consider a = (5)10 = (0101)2  Then b = ~a will be 10 that can be calculated as inverting each bit as shown below: a = 0101 ---------- b = 1010 b = (0111)2 = (10)10
  • 25. Bitwise Operator  Binary << (Left Shift) Operator:  This operator shift the each bit of the operand to left.  It requires two operand  Left operand on which operation is to be performed  Right operand to specify how many times bits are shifted by 1.  Let us consider a = (5)10 = (0101)2  Then b = a << 2 will be 4 that can be calculated as shown below a = 0101 ---------- b = 1010 ---------- b = 0100 b = (0100)2 = (4)10
  • 26. Bitwise Operator  Binary >> (Right Shift) Operator:  This operator shift the each bit of the operand to right.  It requires two operand  Left operand on which operation is to be performed  Right operand to specify how many times bits are shifted by 1.  Let us consider a = (5)10 = (0101)2  Then b = a >> 2 will be 1 that can be calculated as shown below a = 0101 ---------- b = 0010 ---------- b = 0001 b = (0001)2 = (1)10
  • 27. Assignment Operator  = (Simple Assignment) Operator  += (Add AND Assignment) Operator  -= (Subtract AND Assignment) Operator  *= (Multiply AND Assignment) operator  /= (Divide AND Assignment) operator  %= (Modulus AND Assignment) operator  <<= (Left Shift AND Assignment) operator  >>= (Right Shift AND Assignment) operator  &= (Bitwise AND and Assignment) operator  |= (Bitwise OR and Assignment) operator  ^= (Bitwise XOR and Assignment) operator
  • 28. Assignment Operator  = (Simple Assignment) operator: This operator assign the value of the operand or value returned after executing an expression on it’s right to the operand to it’s left.  Let us consider a = 5, b = 3, c = 0  If we write c = a + b, then c will be 8  And if we write c = a, then c will be 5
  • 29. Assignment Operator  += (Add AND Assignment) operator: This operator add the operand on it’s both sides and assign the result to the operand on it’s left.  Let us consider a = 5, b = 3, c = 2  If we write c += a + b, then c will be 10,  If we write c+= a, then c will be 7,  And if we write c += 2, then c will be 4.
  • 30. Assignment Operator  -= (Subtract AND Assignment) operator: This operator subtract the operand on it’s right from the left operand and assign the result to the operand on it’s left.  Let us consider a = 5, b = 3, c = 9  If we write c -= a + b, then c will be 1,  If we write c-= a, then c will be 4,  And if we write c -= 2, then c will be 7.
  • 31. Assignment Operator  *= (Multiply AND Assignment) operator: This operator Multiply the operand on it’s both sides and assign the result to the operand on it’s left.  Let us consider a = 5, b = 3, c = 2  If we write c *= a + b, then c will be 16,  If we write c*= a, then c will be 10,  And if we write c *= 3, then c will be 6.
  • 32. Assignment Operator  /= (Divide AND Assignment) operator: This operator divide the operand on the left with the right operand and assign the quotient to the operand on it’s left.  Let us consider a = 2, b = 3, c = 10  If we write c /= a + b, then c will be 2,  If we write c/= a, then c will be 5,  And if we write c /= 5, then c will be 2.
  • 33. Assignment Operator  %= (Modulus AND Assignment) operator: This operator divide the operand on the left with the right operand and assign the remainder to the operand on it’s left.  Let us consider a = 2, b = 3, c = 10  If we write c %= a + b, then c will be 0,  If we write c%= a, then c will be 0,  And if we write c %= 3, then c will be 1.
  • 34. Assignment Operator  <<= (Left Shift AND Assignment) operator: This operator shift bits of the left operand to left by the value of right operand and assign the result to the operand on it’s left.  Let us consider a = 2, b = 1  If we write a<<=b, then a will be 4,  If we write b<<=3, then b will be 8.
  • 35. Assignment Operator  >>= (Right Shift AND Assignment) operator: This operator shift bits of the left operand to right by the value of right operand and assign the result to the operand on it’s left.  Let us consider a = 2, b = 1  If we write a>>=b, then a will be 1,  If we write a>>=2, then b will be 0.
  • 36. Assignment Operator  &= (Bitwise AND and Assignment) operator: This operator performs the AND operation on bits of the left operand with right operand and assign the result to the operand on it’s left.  Let us consider a = 5, b = 3  If we write a&=b, then a will be 1,  If we write a&=2, then b will be 0.
  • 37. Assignment Operator  |= (Bitwise OR and Assignment) operator: This operator performs the OR operation on bits of the left operand with right operand and assign the result to the operand on it’s left.  Let us consider a = 5, b = 3  If we write a|=b, then a will be 7,  If we write a|=2, then b will be 7.
  • 38. Assignment Operator  ^= (Bitwise XOR and Assignment) operator: This operator performs the XOR operation on bits of the left operand with right operand and assign the result to the operand on it’s left.  Let us consider a = 5, b = 3  If we write a^=b, then a will be 6,  If we write a^=2, then b will be 7.
  • 39. Misc. Operator  sizeof Operator  & (referencing) Operator  * (dereferencing) Operator  ? : (Turnery Operator)
  • 40. Misc. Operator  sizeof Operator: This operator takes operand(variable name/data type keyword) as parameter and return the memory size consume by the operand in bytes.  Let us assume a as integer variable  Then sizeof(a) will return 4 (for 32bit C compilers) or 2(for 16bit C compilers).  Similarly sizeof(float) will return 4, sizeof(char) will return 1 etc.
  • 41. Misc. Operator  & (referencing/address) Operator: It uses only one operand on it’s right and it returns the memory address of the operand as unsigned integer data type.  printf(“%u”, &a); will display 6422316(may be different on different machine & every execution) on the console.  * (dereferencing) Operator: It is pointer to the variable. This operator used to declare the pointer variable & extracting the value stored at the address stored in pointer variable.  Let us assume a = 10, *b = &a,  if we write c = *b then c will be 10.
  • 42. Misc. Operator  ? : (Conditional) Operator: This operator requires three expressions  1. Conditional expression  2. Expression to execute if condition is true  3. Expression to execute if condition is false  Syntax: (condition) ? (Expression for true) : (expression for false);  Let us assume a = 5, b = 1  If c = (a > b) ? a : b; then value of c will be 5  If c = (a < b) ? a : b; then value of c will be 1