Operators in C++

An expression consists of variables and constants separated by Operators in C++. There are mainly 8 types of Operators in C++ are given as follows :

  • Arithmetic Operators
  • Relational Operators
  • Logical Operators
  • Increment and decrement operators
  • Pointer Operators
  • Assignment Operators
  • Bitwise Operators
  • Misc Operators

    1. Arithmetic Operators : Arithmetic Operators are used to perform arithmetic operations.

    2. Relational Operators : Relational Operators are used to compare the values of operands to produce a logical value. It is a type of bool so, a logical is either true or false.

    3. Logical Operators : Logical Operators combine two or more relational operators or expressions and produce a logical value or results.
    Example :

    x>y && x==5
    x==5 || y==7

    4. Increment and decrement operators : Increment operator (++) is used to increase the value of an integer or char variable by 1. Decrement operator (- -) is used to reduce the value of an integer or char variable by 1
    x = 15;
    x++ or ++x will produce the result x = 16
    x = 15;
    x- – or – -x will produce the result x = 14

    5. Pointer Operators : Pointer Operators produces address values.
    Example :

    where a is a variable and ptr is a pointer.

    6. Assignment Operators : In C++, there are three types of Assignment Operators are given as below :
    (i) Chained Operators : A chained operator is used for instance variable at the time of declaration. It can’t used to initialize varables.


    (ii) Embedded Operators :

    (b=10) is an assignement operator that is known as Embedded Operator, 
    Here the value 10 is assigned to b and then the result 10+5=15 is assigned to a.

    (iii) Compound Operators : In C++, compound operator is a combination of the assignment operator with a binary arithmetic operator.

    The operator += is known as Compound Assignment Operator.

    7. Bitwise Operators : Bitwise Operators are used to manipulate data at bit level. They are basically used for testing or shifting bits.
    Example :

    a<<4   // shift four bit position to left
    b>> 2  // shift two bit position to right

    Recommended Posts:

        1. Concepts of OOP
        2. C++ input output functions
        3. Data Types in C++
        4. Operators in C++
        5. C++ Control Statements | if-else, switch, for, while and do-while
        6. Call by Value and Call by Reference in C++
        7. Inline Function in C++
        8. Default Arguments in C++
        9. Function Overloading in C++
        10. C++ Program to Find Factorial of Number
        11. C++ Program to Solve Tower of Hanoi using Recursion