- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Equality Operators: == and != in C++
The equality operators in C++ are is equal to(==) and is not equal to(!=). They do the task as they are named. The binary equality operators compare their operands for strict equality or inequality. The equality operators, equal to (==) and not equal to (!=), have lower precedence than the relational operators, but they behave similarly. The result type for these operators is bool.
The equal-to operator (==) returns true (1) if both operands have the same value; otherwise, it returns false (0). The not-equal-to operator (!=) returns true if the operands do not have the same value; otherwise, it returns false.
example
#include <iostream> using namespace std; int main() { // For printing true and false as true and false in case of a bool result cout << boolalpha << "The true expression 3 != 2 yields: " << (3 != 2) << endl << "The false expression 20 == 10 yields: " << (20 == 10) << endl; }
Output
This gives the output −
The true expression 3 != 2 yields: true The false expression 20 == 10 yields: false
Advertisements