SlideShare una empresa de Scribd logo
1 de 21
An operator is a symbol that
tells the compiler to perform
  specific mathematical or
    logical manipulations.
C++   is    rich   in   built-in
operators and provides following
type of operators:
    •Unary Operator
    •Arithmetic Operators
    •Relational Operators
    •Logical Operators
    •Bitwise Operators
    •Assignment Operators
    •Misc Operators
Unary Operator Requires single operand
item to perform operation
Assume variable A holds 10 then:


Operator   Description                Example
                                      A++ or ++A will give
++         Adds two operands
                                      11

           Subtracts second operand
--                                  A-- or --A will give 9
           from the first
There   are    following   arithmetic                      operators
supported by C++ language:
Assume variable A holds 10 and variable B holds
20 then:
Operator   Description                         Example
+          Adds two operands                   A + B will give 30
           Subtracts second operand from the
-                                            A - B will give -10
           first
*          Multiply both operands              A * B will give 200
/          Divide numerator by de-numerator B / A will give 2
           Modulus Operator and remainder
%                                              B % A will give 0
           of after an integer division
There   are    following   relational   operators
supported by C++ language.
Assume variable A holds 10 and variable B holds
20 then:
Opera
      Description                                                              Example
tor

      Checks if the value of two operands is equal or not, if yes then         (A == B) is
==
      condition becomes true.                                                  not true.

      Checks if the value of two operands is equal or not, if values are not (A != B) is
!=
      equal then condition becomes true.                                     true.


      Checks if the value of left operand is greater than the value of right   (A > B) is
 >
      operand, if yes then condition becomes true.                             not true.


      Checks if the value of left operand is less than the value of right      (A < B) is
 <
      operand, if yes then condition becomes true.                             true.

      Checks if the value of left operand is greater than or equal to the      (A >= B) is
 >=
      value of right operand, if yes then condition becomes true.              not true.

      Checks if the value of left operand is less than or equal to the value   (A <= B) is
 <=
      of right operand, if yes then condition becomes true.                    true.
There are following logical operators supported
by C++ language.
 Assume variable A holds 1 and variable B holds 0
 then:
 Operator Description                                                   Example

          Called Logical AND operator. If both the operands are non
 &&                                                                     (A && B) is false.
          zero then condition becomes true.


          Called Logical OR Operator. If any of the two operands is
 ||                                                                     (A || B) is true.
          non zero then condition becomes true.


          Called Logical NOT Operator. Use to reverses the logical
 !        state of its operand. If a condition is true then Logical NOT !(A && B) is true.
          operator will make false.
The Bitwise operators supported by C++ language
    are listed in the following table.
    Assume variable A holds 60 and variable B
    holds 13 then:
Operator   Description                                                                 Example
           Binary AND Operator copies a bit to the result if it exists in both         (A & B) will give 12 which is
&
           operands.                                                                   0000 1100
                                                                                       (A | B) will give 61 which is
|          Binary OR Operator copies a bit if it exists in either operand.
                                                                                       0011 1101
           Binary XOR Operator copies the bit if it is set in one operand but not      (A ^ B) will give 49 which is
^
           both.                                                                       0011 0001
           Binary Ones Complement Operator is unary and has the effect of              (~A ) will give -60 which is
~
           'flipping' bits.                                                            1100 0011

           Binary Left Shift Operator. The left operands value is moved left by the    A << 2 will give 240 which is
<<
           number of bits specified by the right operand.                              1111 0000


           Binary Right Shift Operator. The left operands value is moved right by the A >> 2 will give 15 which is
>>
           number of bits specified by the right operand.                             0000 1111
There   are    following   assignment   operators
supported by C++ language:
Oper
     Description                                                                            Example
ator

     Simple assignment operator, Assigns values from right side operands to left side       C = A + B will assign
=
     operand                                                                                value of A + B into C
     Add AND assignment operator, It adds right operand to the left operand and assign the C += A is equivalent to
+=
     result to left operand                                                                C=C+A
     Subtract AND assignment operator, It subtracts right operand from the left operand     C -= A is equivalent to
-=
     and assign the result to left operand                                                  C=C-A
     Multiply AND assignment operator, It multiplies right operand with the left operand    C *= A is equivalent to
*=
     and assign the result to left operand                                                  C=C*A
     Divide AND assignment operator, It divides left operand with the right operand and     C /= A is equivalent to
/=
     assign the result to left operand                                                      C=C/A
     Modulus AND assignment operator, It takes modulus using two operands and assign        C %= A is equivalent
%=
     the result to left operand                                                             to C = C % A
                                                                                            C <<= 2 is same as C =
<<= Left shift AND assignment operator
                                                                                            C << 2
                                                                                            C >>= 2 is same as C =
>>= Right shift AND assignment operator
                                                                                            C >> 2
                                                                                            C &= 2 is same as C =
&=   Bitwise AND assignment operator
                                                                                            C&2
                                                                                            C ^= 2 is same as C =
^=   bitwise exclusive OR and assignment operator
                                                                                            C^2
                                                                                            C |= 2 is same as C = C
|=   bitwise inclusive OR and assignment operator
                                                                                            |2
There are few other operators supported by C++ Language.
Operator            Description
                    Size of operator returns the size of a variable. For example size of(a), where a is
Size of
                    integer, will return 4.
                    Conditional operator. If Condition is true ? then it returns value X : otherwise
Condition ? X : Y
                    value Y
                    Comma operator causes a sequence of operations to be performed. The value of
,                   the entire comma expression is the value of the last expression of the comma-
                    separated list.
. (dot) and ->      Member operators are used to reference individual members of classes,
(arrow)             structures, and unions.
                    Casting operators convert one data type to another. For example, int(2.2000)
Cast
                    would return 2.
                    Pointer operator & returns the address of an variable. For example &a; will give
&
                    actual address of the variable.
                    Pointer operator * is pointer to a variable. For example *var; will pointer to a
*
                    variable var.
*Expression in C++ is form when we combine
operands (variables and constant) and C++
Operators.“
*Expression can also be defined as:
"Expression in C++ is a combination of
Operands and Operators.“
*Operands in C++ Program are those values
on which we want to perform perform
operation.
"An expression in which arithmetic
operators   are   used  is  called
arithmetic expression“.
For example an arithmetic expression
is look just like that a+b=5
"A relational operator with constants and
variables makes relational expression or An
expressions in which relational operators are use
is called relational expression.
Points about relational operators :-
1.Relational operators are use to compare values.
2.All the expressions evaluates from left to
right.
3.There are six relational operators in C++
programming (>,<,>=,<=,==,!=).
4.These operators evaluates results true or
false.
5.False statement represent by 0 and True
statement represent by 1.
6.These operators evaluate at statement level and
has no preference.
1. There are three logical operators And( && ),or( || ) these two
both are binary operator and not( ! ) is u nary operator.
2. More than one relation expression are combine by using logical
                             operators.
3. The expression will evaluate from left to right if more than one
relation expression are use.
Example 1 . write the corresponding C++
expression for the following mathematical
expression ?
1.2 – ye2y + 4y
2.P + q /(r + s)4
Solution = 1. 2-y*exp(2*y)+4*y
          = 2. p+q/ pow ((r+s),4)
Operators and Expression
Operators and Expression

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

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++
 
C – operators and expressions
C – operators and expressionsC – operators and expressions
C – operators and expressions
 
Operators and expressions in C++
Operators and expressions in C++Operators and expressions in C++
Operators and expressions in C++
 
Operators in C & C++ Language
Operators in C & C++ LanguageOperators in C & C++ Language
Operators in C & C++ Language
 
11operator in c#
11operator in c#11operator in c#
11operator in c#
 
Operators in C/C++
Operators in C/C++Operators in C/C++
Operators in C/C++
 
Operators
OperatorsOperators
Operators
 
Basic c operators
Basic c operatorsBasic c operators
Basic c operators
 
C Prog. - Operators and Expressions
C Prog. - Operators and ExpressionsC Prog. - Operators and Expressions
C Prog. - Operators and Expressions
 
operators and expressions in c++
 operators and expressions in c++ operators and expressions in c++
operators and expressions in c++
 
operators in c++
operators in c++operators in c++
operators in c++
 
Operator in c programming
Operator in c programmingOperator in c programming
Operator in c programming
 
C# operators
C# operatorsC# operators
C# operators
 
Operator.ppt
Operator.pptOperator.ppt
Operator.ppt
 
Expression and Operartor In C Programming
Expression and Operartor In C Programming Expression and Operartor In C Programming
Expression and Operartor In C Programming
 
Operators in C++
Operators in C++Operators in C++
Operators in C++
 
C operator and expression
C operator and expressionC operator and expression
C operator and expression
 
Operators
OperatorsOperators
Operators
 
Basic c operators
Basic c operatorsBasic c operators
Basic c operators
 
Constructor and destructors
Constructor and destructorsConstructor and destructors
Constructor and destructors
 

Similar a Operators and Expression

Similar a Operators and Expression (20)

Session03 operators
Session03 operatorsSession03 operators
Session03 operators
 
07 ruby operators
07 ruby operators07 ruby operators
07 ruby operators
 
itft-Operators in java
itft-Operators in javaitft-Operators in java
itft-Operators in java
 
Bit shift operators
Bit shift operatorsBit shift operators
Bit shift operators
 
java operators
 java operators java operators
java operators
 
Python operators part2
Python operators part2Python operators part2
Python operators part2
 
Programming C Part 02
Programming C Part 02Programming C Part 02
Programming C Part 02
 
Java basic operators
Java basic operatorsJava basic operators
Java basic operators
 
Java basic operators
Java basic operatorsJava basic operators
Java basic operators
 
Operator 04 (js)
Operator 04 (js)Operator 04 (js)
Operator 04 (js)
 
C programming operators
C programming operatorsC programming operators
C programming operators
 
Python : basic operators
Python : basic operatorsPython : basic operators
Python : basic operators
 
Operators in Python
Operators in PythonOperators in Python
Operators in Python
 
Operators and it's type
Operators and it's type Operators and it's type
Operators and it's type
 
C operators
C operatorsC operators
C operators
 
Opeartor &amp; expression
Opeartor &amp; expressionOpeartor &amp; expression
Opeartor &amp; expression
 
Computer programming 2 Lesson 7
Computer programming 2  Lesson 7Computer programming 2  Lesson 7
Computer programming 2 Lesson 7
 
C# Fundamentals - Basics of OOPS - Part 2
C# Fundamentals - Basics of OOPS - Part 2C# Fundamentals - Basics of OOPS - Part 2
C# Fundamentals - Basics of OOPS - Part 2
 
Java unit1 b- Java Operators to Methods
Java  unit1 b- Java Operators to MethodsJava  unit1 b- Java Operators to Methods
Java unit1 b- Java Operators to Methods
 
COM1407: C Operators
COM1407: C OperatorsCOM1407: C Operators
COM1407: C Operators
 

Último

Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4JOYLYNSAMANIEGO
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4MiaBumagat1
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfVanessa Camilleri
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptxMusic 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptxleah joy valeriano
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
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
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptxiammrhaywood
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
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
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfErwinPantujan2
 
Integumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptIntegumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptshraddhaparab530
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 
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
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYKayeClaireEstoconing
 

Último (20)

Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdf
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptxMusic 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.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
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
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
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
 
Integumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptIntegumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.ppt
 
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
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 
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
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
 

Operators and Expression

  • 1.
  • 2. An operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations.
  • 3. C++ is rich in built-in operators and provides following type of operators: •Unary Operator •Arithmetic Operators •Relational Operators •Logical Operators •Bitwise Operators •Assignment Operators •Misc Operators
  • 4. Unary Operator Requires single operand item to perform operation Assume variable A holds 10 then: Operator Description Example A++ or ++A will give ++ Adds two operands 11 Subtracts second operand -- A-- or --A will give 9 from the first
  • 5. There are following arithmetic operators supported by C++ language: Assume variable A holds 10 and variable B holds 20 then: Operator Description Example + Adds two operands A + B will give 30 Subtracts second operand from the - A - B will give -10 first * Multiply both operands A * B will give 200 / Divide numerator by de-numerator B / A will give 2 Modulus Operator and remainder % B % A will give 0 of after an integer division
  • 6. There are following relational operators supported by C++ language. Assume variable A holds 10 and variable B holds 20 then:
  • 7. Opera Description Example tor Checks if the value of two operands is equal or not, if yes then (A == B) is == condition becomes true. not true. Checks if the value of two operands is equal or not, if values are not (A != B) is != equal then condition becomes true. true. Checks if the value of left operand is greater than the value of right (A > B) is > operand, if yes then condition becomes true. not true. Checks if the value of left operand is less than the value of right (A < B) is < operand, if yes then condition becomes true. true. Checks if the value of left operand is greater than or equal to the (A >= B) is >= value of right operand, if yes then condition becomes true. not true. Checks if the value of left operand is less than or equal to the value (A <= B) is <= of right operand, if yes then condition becomes true. true.
  • 8. There are following logical operators supported by C++ language. Assume variable A holds 1 and variable B holds 0 then: Operator Description Example Called Logical AND operator. If both the operands are non && (A && B) is false. zero then condition becomes true. Called Logical OR Operator. If any of the two operands is || (A || B) is true. non zero then condition becomes true. Called Logical NOT Operator. Use to reverses the logical ! state of its operand. If a condition is true then Logical NOT !(A && B) is true. operator will make false.
  • 9. The Bitwise operators supported by C++ language are listed in the following table. Assume variable A holds 60 and variable B holds 13 then: Operator Description Example Binary AND Operator copies a bit to the result if it exists in both (A & B) will give 12 which is & operands. 0000 1100 (A | B) will give 61 which is | Binary OR Operator copies a bit if it exists in either operand. 0011 1101 Binary XOR Operator copies the bit if it is set in one operand but not (A ^ B) will give 49 which is ^ both. 0011 0001 Binary Ones Complement Operator is unary and has the effect of (~A ) will give -60 which is ~ 'flipping' bits. 1100 0011 Binary Left Shift Operator. The left operands value is moved left by the A << 2 will give 240 which is << number of bits specified by the right operand. 1111 0000 Binary Right Shift Operator. The left operands value is moved right by the A >> 2 will give 15 which is >> number of bits specified by the right operand. 0000 1111
  • 10. There are following assignment operators supported by C++ language:
  • 11. Oper Description Example ator Simple assignment operator, Assigns values from right side operands to left side C = A + B will assign = operand value of A + B into C Add AND assignment operator, It adds right operand to the left operand and assign the C += A is equivalent to += result to left operand C=C+A Subtract AND assignment operator, It subtracts right operand from the left operand C -= A is equivalent to -= and assign the result to left operand C=C-A Multiply AND assignment operator, It multiplies right operand with the left operand C *= A is equivalent to *= and assign the result to left operand C=C*A Divide AND assignment operator, It divides left operand with the right operand and C /= A is equivalent to /= assign the result to left operand C=C/A Modulus AND assignment operator, It takes modulus using two operands and assign C %= A is equivalent %= the result to left operand to C = C % A C <<= 2 is same as C = <<= Left shift AND assignment operator C << 2 C >>= 2 is same as C = >>= Right shift AND assignment operator C >> 2 C &= 2 is same as C = &= Bitwise AND assignment operator C&2 C ^= 2 is same as C = ^= bitwise exclusive OR and assignment operator C^2 C |= 2 is same as C = C |= bitwise inclusive OR and assignment operator |2
  • 12. There are few other operators supported by C++ Language. Operator Description Size of operator returns the size of a variable. For example size of(a), where a is Size of integer, will return 4. Conditional operator. If Condition is true ? then it returns value X : otherwise Condition ? X : Y value Y Comma operator causes a sequence of operations to be performed. The value of , the entire comma expression is the value of the last expression of the comma- separated list. . (dot) and -> Member operators are used to reference individual members of classes, (arrow) structures, and unions. Casting operators convert one data type to another. For example, int(2.2000) Cast would return 2. Pointer operator & returns the address of an variable. For example &a; will give & actual address of the variable. Pointer operator * is pointer to a variable. For example *var; will pointer to a * variable var.
  • 13.
  • 14. *Expression in C++ is form when we combine operands (variables and constant) and C++ Operators.“ *Expression can also be defined as: "Expression in C++ is a combination of Operands and Operators.“ *Operands in C++ Program are those values on which we want to perform perform operation.
  • 15.
  • 16. "An expression in which arithmetic operators are used is called arithmetic expression“. For example an arithmetic expression is look just like that a+b=5
  • 17. "A relational operator with constants and variables makes relational expression or An expressions in which relational operators are use is called relational expression. Points about relational operators :- 1.Relational operators are use to compare values. 2.All the expressions evaluates from left to right. 3.There are six relational operators in C++ programming (>,<,>=,<=,==,!=). 4.These operators evaluates results true or false. 5.False statement represent by 0 and True statement represent by 1. 6.These operators evaluate at statement level and has no preference.
  • 18. 1. There are three logical operators And( && ),or( || ) these two both are binary operator and not( ! ) is u nary operator. 2. More than one relation expression are combine by using logical operators. 3. The expression will evaluate from left to right if more than one relation expression are use.
  • 19. Example 1 . write the corresponding C++ expression for the following mathematical expression ? 1.2 – ye2y + 4y 2.P + q /(r + s)4 Solution = 1. 2-y*exp(2*y)+4*y = 2. p+q/ pow ((r+s),4)