Simple Assignment Operators Example Program In C++
Assignment Operators
They are used to assign the result of an expression to a variable.
Syntax
identifier = Expression
There are five assignment operators. They are,
a=a+1 a+=1
a=a- 1 a-= 1
a=a*2 a*=2
a=a/2 a/= 2
a=a%2 a%=2
Advantages:
- Left-hand side operator need not repeat.
- Easy to Read
- More Efficient
Example For C assignment operator
// Header Files
#include<iostream>
#include<conio.h>
//Main Function
using namespace std;
int main ()
{
// Variable Declaration
int a = 10;
// = Operator
int b = a;
cout << "Simple Assignment Operators Example Program \n";
cout<<"\nb = "<<b;
// += Operator
b += 10;
cout<<"\nb += 10;b = "<<b;
// -= Operator
b -=5;
cout<<"\nb -=5;b = "<<b;
// *= Operator
b *=4;
cout<<"\nb *=4;b = "<<b;
// /= Operator
b /=2;
cout<<"\nb /=2;b = "<<b;
// Wait For Output Screen
getch();
//Main Function return Statement
return 0;
}
Sample Output
Simple Assignment Operators Example Program
b = 10
b += 10;b = 20
b -=5;b = 15
b *=4;b = 60
b /=2;b = 30
C++ Operator Example Programs
- Simple Arithmetic Operators Example Program In C++
- Simple Relational Operator Example Program In C++
- Simple Logical Operators Example Program In C++
- Simple Assignment Operators Example Program In C++
- Simple Unary Operators Example Program In C++
- Simple Conditional or Ternary Operators Example Program In C++
- Simple Comma Operators Example Program In C++
- Simple Scope Resolution Operator Example Program In C++
- Simple new Memory Allocation Operator Example Program In C++
- Simple delete Memory Releasing Operator Example Program In C++
Read More Articles
- Simple Merge Sort Program in C++
- Scope Resolution Operator In C++
- Simple Program for Virtual Functions Using C++ Programming
- Simple Class Example Program For Find Prime Number In C++
- Simple Example Program For Parameterized Constructor In C++
- Define Constructor in Outside Class Example Program In C++
- Simple Example Program For Copy Constructor In C++
- Simple Program for Function Overloading Using C++ Programming
- Simple Program for Single Inheritance Using C++ Programming
- Simple Program for Inline Function without Class Using C++ Programming
- Simple Example Program For Constructor Overloading In C++
- Factorial Using Function Example Program In C++
- Simple Example Program for Inline Function Using C++ Programming
- Simple Addition ( Add Two Integers ) Example Program
- Simple Example Program For Constructor In C++
- Simple Program for Read user Input Using cin
- Factorial Using Loop Example Program In C++
- Simple Stack Program in C++ Programming
- Simple Program for Friend Function Using C++ Programming
- Simple Program for Static Data and Member Function Using C++ Programming
- Simple Program for Unary Operator Overloading Using C++ Programming
- Simple Program for Multiple Inheritance Using C++ Programming
- Do While Loop Example Program In C++
- Simple Copy Constructor Example Program For Find Factorial In C++
- Simple Program for Virtual Base Class Using C++ Programming