Learn Best C++ Operators All List in 2023

Operators in C++ with Example: What are the 7 types of Operators?

C++ Operator: Operator is a special symbol which is used to perform logical or mathematical operation on data or variable. operand is a or variable on which the operation is to be performed.

C++, an operator is a symbol that performs a specific operation on one or more operands (the values or variables on which the operator is performed). Operators are used to manipulate and retrieve values stored in variables, as well as to perform various types of operations on them.

These operators can be used to create expressions, which can be assigned to variables or passed as arguments to functions. They can also be used in control structures such as if-else statements and loops, to control the flow of a program.

Learn Best C++ Operators All List in 2023
Learn Best C++ Operators All List in 2023

    Types of Operators in C++ with Example

    1. Arithmetic operators: These operators perform basic arithmetic operations, such as addition, subtraction, multiplication, and division.

    2. Relational operators: These operators compare two values and return a Boolean value (true or false) based on the relationship between the values.

    3. Logical operators: These operators perform logical operations, such as AND, OR, and NOT.

    4. Bitwise operators: These operators perform operations on individual bits of a binary number.

    5. Assignment operators: These operators assign a value to a variable.

    6. Increment and decrement operators: These operators increase or decrease the value of a variable by 1.

    7. Conditional operators: The conditional operator, also known as the ternary operator, is an operator in C++ that allows you to assign a value to a variable based on a certain condition. 

    8. Special operators: Special operator is an address store(&) and sizeof() value store in special operator. 

    Arithmetic Operators in CPP

    C++ programming language, the following arithmetic operators are available:
    1. Addition operator.
    2. Subtraction operator.
    3. Multiplication operator.
    4. Division operator.
    5. Modulus operator.

    Arithmetic Operator Table in C++ Programming
    SymbolsOperationsExamples
    +Additionx+y
    -Subtractionx-y
    *Multiplicationx*y
    /Divisionx/y
    %Modulusx%y

    Arithmetic Operators Program in CPP

    #include<iostream.h>

    #include<conio.h>

    void main()

    {

    clrscr();

    int f,s,add,sub,mul,div,mod;

    cout<<"Enter First Number:";

    cin>>f;

    cout<<"Enter second Number:";

    cin>>f;

    add=f+s;

    sub=f-s;

    mul=f*s;

    div=f/s;

    mod=f%s;

    cout<<"Addition:"<<add<<endl;

    cout<<"Subtraction:"<<sub<<endl;

    cout<<"Multiplication:"<<mul<<endl;

    cout<<"Division:"<<div<<endl;

    cout<<"Modulus:"<<mod<<endl;

    getch();

    }


    **********OUTPUT**********

    Enter First Number:5

    Enter Second Number:2

    Addition:7

    Subtraction:3

    Multiplication:10

    Division:2.5

    Modulus:1


    Explain Relational Operators in C++

    Relational Operator: A computer programming, relational operators are operators that are used to compare values and determine the relationship between those values. There are several relational operators in c++ programming languages.
    1. Equal to.
    2. Not equal to.
    3. Greater than.
    4. Less than.
    5. Greater than or equal to.
    6. Less than or equal to.

    Relational Operator Table in C++ Programming
    SymbolsOperationsExamples
    =Equalx=y
    !=Not Equal Tox!=y
    >Greater Thanx>y
    <Less Thanx<y
    >=Greater Than or Equal Tox>=y
    <=Less Than or Equal Tox<=y

    What is Relational Operator with Example

    #include<iostream.h>

    #include<conio.h>

    int main()

    {

    int f,s;

    cout<<"Enter First Number:";

    cin>>f;

    cout<<"Enter second Number:");

    cin>>s;

    cout<<"Equal To:"<<f==s<<endl;

    cout<<"Greater Than:"<<f>s<<endl;

    cout<<"Less Than:"<<f<s<<endl;

    cout<<"Greater Than or Equal To:"<<f>=s<<endl;

    cout<<"Less Than or Equal To:"<<f<=s<<endl;

    cout<<"Not Equal To:"<<f!=s<<endl;

    }


    **********OUTPUT**********

    Enter First Number:5

    Enter second Number:3

    Equal To:0

    Greater Than:1

    Less Than:0

    Greater Than or Equal To:1

    Less Than or Equal To:0

    Not Equal To:1


    Logical Operators in C++ Programming Language

    Logical operators: A C++ programming language, there are several logical operators that you can use to perform logical operations on expressions.

    1. AND (&&) operator: This operator returns true if both the operands are true, otherwise it returns false.

    2. OR (||) operator: This operator returns true if either of the operands is true, otherwise it returns false.

    3. NOT (!) operator: This operator returns true if the operand is false, and returns false if the operand is true.

    Logical Operator Table in C++ Programming
    SymbolsOperationsExamples
    &&Logical ANDx&&y
    ||Logical ORx||y
    !Logical NOTx!y

    Logical Operator in C++ with Example Program

    #include<iostream.h>

    #include<conio.h>

    int main()

    {

    int f,s;

    cout<<"Enter First Number:";

    cin>>f;

    printf("Enter second Number:";

    cin>>s;

    cout<<"Logical AND Operator:"<<f&&s<<endl;

    cout<<"Logical OR Operator:"<<f||s<<endl;

    cout<<"Logical NOT Operator:<<f!=s;


    }


    **********OUTPUT**********

    Enter First Number:5

    Enter second Number:3

    Logical AND Operator:0

    Logical OR Operator:1

    Logical NOT Operator:1


    Bitwise Operators in C++ Definition

    Bitwise operators: A C++ programming language, there are several bitwise operators that you can use to perform bitwise operations on integers.

    1. Bitwise AND (&) operator: This operator performs a bitwise AND operation on two operands. It returns 1 if both the operands are 1, and returns 0 otherwise.

    2. Bitwise OR (|) operator: This operator performs a bitwise OR operation on two operands. It returns 1 if either of the operands is 1, and returns 0 otherwise.

    3. Bitwise XOR (^) operator: This operator performs a bitwise exclusive OR operation on two operands. It returns 1 if either of the operands is 1, but not both, and returns 0 otherwise.

    4. Bitwise NOT (~) operator: This operator performs a bitwise NOT operation on an operand. It inverts all the bits of the operand.

    5. Bitwise left shift (<<) operator: This operator shifts the bits of an operand to the left by a specified number of positions.

    6. Bitwise right shift (>>) operator: This operator shifts the bits of an operand to the right by a specified number of positions.

    Bitwise Operator Table in C++ Programming
    SymbolsOperationsExamples
    &Bitwise ANDx&y
    |Bitwise ORx|y
    ^Bitwise XORx^y
    ~Bitwise NOTx~y
    <<Bitwise LEFT SHIFTx<<2
    >>Bitwise RIGHT SHIFTx>>2

    Bitwise Operators in C++ with Examples

    #include<iostream.h>

    #include<conio.h>

    int main()

    {

    int f,s;

    cout<<"Enter First Number:";

    cin>>f;

    cout<<"Enter second Number:";

    cin>>s;

    cout<<"Bitwise AND Operator:<<"f&s<<endl;

    cout<<"Bitwise OR Operator:"<<f|s<<endl;

    cout<<"Bitwise  XOR Operator:"<<f^s<<endl;

    cout<<"Bitwise  NOT Operator:"<<f~s<<endl;

    cout<<"Bitwise  LEFT SHIFT Operator:"<<f<<1<<endl;

    cout<<"Bitwise  RIGHT SHIFT Operator:"<<f>>1;


    }


    **********OUTPUT**********

    Enter First Number:10

    Enter second Number:5

    Bitwise AND Operator:0

    Bitwise OR Operator:15

    Bitwise  XOR Operator:15

    Bitwise  NOT Operator:-11

    Bitwise  LEFT SHIFT Operator:20

    Bitwise  RIGHT SHIFT Operator:5


    Assignment Operator C++ Implementation

    Assignment operators: A C++ programming language, there are several assignment operators that you can use to assign a value to a variable.

    Compound assignment operators: These operators are used to perform an operation and assign the result to a variable in a single statement. The compound assignment operators are:

    1. Addition assignment operator(+=): This operator adds the right operand to the left operand and assigns the result to the left operand.

    2. Subtraction assignment operator(-=): This operator subtracts the right operand from the left operand and assigns the result to the left operand.

    3. Multiplication assignment operator(*=): This operator multiplies the left operand by the right operand and assigns the result to the left operand.

    4. Division assignment operator(/=): This operator divides the left operand by the right operand and assigns the result to the left operand.

    5. Modulus assignment operator(%=): This operator calculates the remainder when the left operand is divided by the right operand and assigns the result to the left operand.

    Assignment Operator Table in C++ Programming
    SymbolsOperationsExamples
    +=Additionx+=y or x=x+y
    -=Subtractionx-=y or x=x+y
    *=Multiplicationx*=y or x=x+y
    /=Divisionx/=y or x=x+y
    %=Modulusx%=y or x=x+y

    Assignment Operators in C++ with Example Program

    #include<iostream.h>

    #include<conio.h>

    void main()

    {

    int a;

    cout<<"Enter First Number:";

    cin>>a;

    cout<<"Assignment Addition:"<<a+=5<<endl;

    cout<<"Assignment Subtraction:"<<a-=5<<endl;

    cout<<"Assignment Multiplication:"<<a*=5<<endl;

    cout<<"Assignment Division:"<<a/=5<<endl;

    cout<<"Assignment Modulus:"<<a%=5;

    }

    getch();

    }


    **********OUTPUT**********

    Enter First Number:7


    Assignment Addition:12

    Assignment Subtraction:7

    Assignment Multiplication:35

    Assignment Division:7

    Assignment Modulus:2


    Increment Decrement Operator Program in C++

    Increment and decrement operators: A C++, there are two increment operators: ++ and --. The ++ operator increases the value of a variable by 1, while the -- operator decreases the value of a variable by 1.

    Pre increment and Post increment Operator in C++ examples
    SymbolsOperationsExamples
    ++Pre-Incrementx++
    --Pre-Decrementx--
    ++Post-Increment++x
    --Post-Decrement--x

    Increment Operator C++ Example

    #include <iostream.h>

    #include<conio.h>

    int main() 

    {

        int x = 10;

        x++;

        cout<<"x is:<<x<<endl;

        ++x; 

        cout<<"x is:"<<x;

        return 0;

    }


    **********OUTPUT**********

    x is 11

    x is 12


    Decrement Operator C++ Example

    #include <iostream.h>

    #include<conio.h>

    int main() 

    {

    int x = 10;

    int y = 5;

    int z = x++ + y;  

    int a = x-- + y; 

    int b = ++x + y;  

    int c = --x + y;

    return 0;

    }


    **********OUTPUT**********

    z is 15

    a is 16

    b is 16

    c is 15


    Use of Conditional Operator in C++

    Conditional Operator: The conditional operator, also known as the ternary operator, is an operator in C++ that allows you to assign a value to a variable based on a certain condition. It is written as "condition ? value1 : value2", and it works as follows:

    1. First, the condition is evaluated.
    2. If the condition is true, the operator returns value1.
    3. If the condition is false, the operator returns value2.

    Conditional Operator in C++ Example Program

    #include <iostream.h>

    #include<conio.h>

    int main() 

    {

        int x = 10

        int y=20;

       x>y?cout<<"x is greater than b":cout<<"b is greater than a";

    }


    **********OUTPUT**********

    b is greater than a


    Special Operators in C++ with Examples

    SymbolsOperationsExamples
    &it is used find addressint a=10;
    cout<<&a;
    *It is used pointer variableint *p;
    sizeof()It Used Memory Sizeint a=10;
    cout<<sizeof(a);


    Post a Comment

    0 Comments