Assignment Operators Examples in C++


Description

Assignment operators are used to assign value to a variable. The left side operand of the assignment operator is a variable and right side operand of the assignment operator is a value. The value on the right side must be of the same data-type of variable on the left side otherwise the compiler will raise an error. Different types of assignment operators are shown below:

Example Program

Here is the simple program for Assignment Operators Examples in C++.

Source Code Example : 1

#include<iostream>
using namespace std;
int main()
{
    int x=10;
    x+=5;
    cout<<"\nValue of x: "<<x;
    return 0;
}
To download raw file Click Here

Output

Value of x: 15

Source Code Example : 2

#include<iostream>
using namespace std;
int main()
{
    int x=10;
    x-=5;
    cout<<"\nValue of x: "<<x;
    return 0;
}
To download raw file Click Here

Output

Value of x: 5

Source Code Example : 3

#include<iostream>
using namespace std;
int main()
{
    int x=10;
    x*=5;
    cout<<"\nValue of x: "<<x;
    return 0;
}
To download raw file Click Here

Output

Value of x: 50

Source Code Example : 4

#include<iostream>
using namespace std;
int main()
{
    int x=10;
    x/=5;
    cout<<"\nValue of x: "<<x;
    return 0;
}
To download raw file Click Here

Output

Value of x: 2

Source Code Example : 5

#include<iostream>
using namespace std;
int main()
{
    int x=10;
    x%=5;
    cout<<"\nValue of x: "<<x;
    return 0;
}
To download raw file Click Here

Output

Value of x: 0

Source Code Example : 6

#include<iostream>
using namespace std;
int main()
{
    int x=10;
    x^=2;
    cout<<"\nValue of x: "<<x;
    return 0;
}
To download raw file Click Here

Output

Value of x: 8

Basic Programs


Flow Control

IF Statement Examples


Switch Case


Goto Statement


Break and Continue


While Loop


Do While Loop


For Loop


Friend Function in C++


String Examples


Array Examples


Structure Examples


Structure & Pointer Examples


Structure & Functions Examples


Enumeration Examples


Template Examples


Functions


Inheritance Examples

Hierarchical Inheritance


Hybrid Inheritance


Multilevel Inheritance


Multiple Inheritance


Single Level Inheritance


Class and Objects

Constructor Example


Destructor Example


Operator Overloading Example


List of Programs


Pointer Examples


Memory Management Examples


Pointers and Arrays


Virtual Function Examples



Learn All in Tamil © Designed & Developed By Tutor Joes