![]() |
| Operators in CPP Programing with Definition |
Operators in C++ With Example Program
Definition of Operators in C++: Operator is a special symbol it can be used to perform logical or mathematical operations performed on data or variables. Operators is very important part of every programming languages because operators is process of our data and provide accurate results.
Types of Operators in C++ with Example
- Arithmetic Operators in CPP
- Relational Operators in CPP
- Logical Operators in CPP
- Assignment Operators in CPP
- Bitwise Operators in CPP
- Increment Operators in CPP
- Decrement Operators in CPP
- Conditional Operators in CPP
- Special Operator in CPP
Arithmetic Operators in C++ Definition
Types of Arithmetic Operators in C++
| Symbols | Operation | Example |
|---|---|---|
| (+) | Addition | (a+b)=> (5+6)=>9 |
| (-) | Subtraction | (a-b)=> (8-3)=>5 |
| (*) | Multiplication | (a*b)=> (5*6)=>30 |
| (/) | Division | (a/b)=> (5/2)=>2.5 |
| (%) | Modulus | (a%b)=> (5%2)=>1 |
Arithmetic Operators in C++ Program
int main(){ int a,b; cout<<"Enter First Number:"; cin>>a; cout<<"Enter Second Number:"; cin>>b; cout<<"Addition of a+b:"<<a+b<<endl; cout<<"Subtraction of a-b:"<<a-b<<endl; cout<<"Multiply of a*b:"<<a*b<<endl; cout<<"Division of a/b:"<<a/b<<endl; cout<<"Modulus of a%b:"<<a%b<<endl; } ============OUTPUT============ Enter First Number: 5 Enter Second Number: 2 Addition of a+b: 7 Subtraction of a-b:3 Multiply of a*b:10 Division of a/b:2.5 Modulus of a%b:1 |
Relational Operators in C++ Language
Relational Operator: A relational operators can be used to performed operation two values compression and results provide true and false. Relational operators compare two variables expression and check relationship than provide results.
Types of Relational Operators
| Symbols | Operation | Example |
|---|---|---|
| (==) | Equal To | (a==b) |
| (>) | Greater Than | (a>b) |
| (<) | Less Than | (a<b) |
| (>=) | Greater Than Or Equal To | (a>=b) |
| (<=) | Less Than Or Equal To | (a<=b) |
| (!=) | Not Equal To | (a!=b) |
Relational Operators Program in C++
int main(){ int a,b; cout<<"Enter First Number:"; cin>>a; cout<<"Enter Second Number:"; cin>>b; cout<<"Equal To a==b:"<<(a==b)<<endl; cout<<"Greater Than a>b:"<<(a>b)<<endl; cout<<"Less Than a<b:"<<(a<b)<<endl; cout<<"Greater Than or Equal To a>=b:"<<(a>=b)<<endl; cout<<"Less Than or Equal To a<=b:"<<(a<=b)<<endl; cout<<"Not Equal To a!=b:"<<(a!=b)<<endl; } ============OUTPUT============ Enter First Number: 5 Enter Second Number: 2 Equal To a==b: 0 Greater Than a>b:1 Less Than a<b:0 Greater Than or Equal To a>=b:1 Less Than or Equal To a<=b:0 Not Equal To:1 |
Logical Operators in C++ Definition
Logical Operator: A logical operators can be used compare two variables and perform logical operations. If the logical condition is true than return 1 and logical condition is false than return 0.
Logical AND Operator: A logical AND operator condition is a both condition are true than result are true. If the any one condition are false then return false.
Logical AND Operator in C++ Program
| #include<stdio.h> using namespace std; int main(){ char username[100]="jiocoding"; char password[100]="12345"; char user[100]; char pwd[100]; cout<<"Enter Username:"; cin>>user; cout<<"Enter Password:"; cin>>pwd; if(strcmp(username,user)==0&&strcmp(password,pwd)==0) { cout<<"Login Successfully"; } else{ cout<<"Username or Password Invalid"; } } ============OUTPUT============ Enter Username: jiocoding Enter Password: 12345 Login Successfully |
Logical OR Operator: A logical OR operator can be used to anyone condition are true than both condition are true. If one condition are false than return true.
Logical OR Operators in C++ Program
using namespace std; int main(){ char username[100]="jiocoding"; char password[100]="12345"; char user[100]; char pwd[100]; cout<<"Enter Username:"; cin>>user; cout<<"Enter Password:"; cin>>pwd; if(strcmp(username,user)==0&&strcmp(password,pwd)==0) { cout<<"Login Successfully"; } else{ cout<<"Username or Password Invalid"; } } ============OUTPUT============ Enter Username: jiocoding Enter Password: 12345654 Login Successfully |
Logical NOT Operator: A logical NOT operator reverses the state means if the condition is true it returns false and if the condition is false it returns true.
How Many Types of Logical Operators
| Symbols | Operation | Example |
|---|---|---|
| (&&) | Logical AND | (a&&b) |
| (||) | Logical OR | (a||b) |
| (!) | Logical NOT | (a!=b) |
Logical Operators in C++ Program
using namespace std; int main(){ char username[100]="jiocoding"; char password[100]="12345"; char user[100]; char pwd[100]; cout<<"Enter Username:"; cin>>user; cout<<"Enter Password:"; cin>>pwd; if(strcmp(username,user)==0&&strcmp(password,pwd)==0) { cout<<"Login Successfully"; } else{ cout<<"Username or Password Invalid"; } } ============OUTPUT============ Enter Username: JIOCODING Enter Password: 12345 Username or Password Invalid |
Assignment Operator in C++ Definition
Assignment Operator: A assignment operator can be used to assign the value of an right side and variable on the left side.
Types of Assignment Operators
| Symbols | Operation | Example |
|---|---|---|
| (=) | (a=b) | (a=b) |
| (+=) | (a+=b) | (a=a+b) |
| (-=) | (a-=b) | (a=a-b) |
| (*=) | (a*=b) | (a=a*b) |
| (/=) | (a/=b) | (a=a/b) |
| (%=) | (a%=b) | (a=a%b) |
Assignment Operator in C++ program
using namespace std; int main(){ int a,b; cout<<"Enter First Number:"; cin>>a; cout<<"Enter Second Number:"; cin>>b; a+=b; cout<<"Assignment Addition of a+=b:"<<a; } ============OUTPUT============ Enter First Number: 8 Enter Second Number: 5 Assignment Addition of a+=b: 13 |
Bitwise Operator Definition
Bitwise Operator: A bitwise operator can be used to perform individual operation bits on integers data. Bitwise operators are used to binary operations performed.
Types of Bitwise Operators
| Symbols | Operation | Example |
|---|---|---|
| (&) | Bitwise AND | (a&b) |
| (|) | Bitwise OR | (a|b) |
| (<<) | Bitwise Shift Left | (a<<b) |
| (>>) | Bitwise Shift Right | (a>>b) |
Bitwise Operators Program in Cpp
using namespace std; int main(){ int a,b; cout<<"Enter First Number:"; cin>>a; cout<<"Enter Second Number:"; cin>>b; cout<<"Bitwise AND operator:"<<(a&b)<<endl; cout <<"Bitwise OR operator:" <<(a|b)<<endl; cout<<"Bitwise Shift Left Operator:"<<(a<<2)<<endl; cout<<"Bitwise Shift Right Operator:"<<(a<<2)<<endl; } ============OUTPUT============ Enter First Number: 5 Enter Second Number: 3 Bitwise AND Operator: 1 Bitwise OR Operator:7 Bitwise Shift Left Operator: 20 Bitwise Shift Right Operator:1 |
Increment and Decrement Operators
Increment Operator: increment or decrement operators can be used to increase 1 value and decrement 1 value. Mostly increment operator commonly used to loops in C++.
Types of Increment and Decrement Operators
| Symbols | Name | Function | Example |
|---|---|---|---|
| (++) | Increment | It increment the value 1 | ++a |
| (--) | Decrement | It Decrement the value 1 | --a |
Increment Operators in C++ Program
using namespace std; int main(){ int a; cout<<"Enter any Number:"; cin>>a; cout<<"Increment Operator of ++a:"<<++a; } ============OUTPUT============ Enter any Number: 5 Increment Operator of ++a:6 |
Decrement Operators in C++ Program
using namespace std; int main(){ int a; cout<<"Enter any Number:"; cin>>a; cout<<"Decrement Operator of --a:"<<--a; getch(); } ============OUTPUT============ Enter any Number: 5 Decrement Operator of --a:4 |
Ternary Operator Definitions
Ternary Operators: A conditional operators can be used to one line operators or ternary operators because it can be used to three operands values.
Ternary Operators in C++ Program
using namespace std; int main(){ 10<5?cout<<"Welcome":cout<<"Jiocoding"; } ============OUTPUT============ Jiocoding |
Special Operators in CPP
Special Operators in CPP
| Symbols | Descriptions | Example |
|---|---|---|
| (&) | It is used to find address of variable. | int x=10; |
| (*) | It is used to declared Pointer Variable. | int *p; |
| (sizeof()) | It can be used find memory size. | int x=5; |
Special Operators in C++ Program
using namespace std; int main(){ int a=10; cout<<"Address of a:"<<&a<<endl; cout<<"Size of a:"<<sizeof(a); } ============OUTPUT============ Address of a:0x6ffe1c Size of a:4 |
Conclusion of Operators in C++ Programming
Conclusion: A C++ operators can be used mathematical operations performed on data variables. I can explain everyone operators including with example if your any query or operator related questions than you can contact me by email or comment.

