🔍 C++ Relational Operators – Compare Values with Ease
Relational operators in C++ are used to compare two values. Think of them as the operators that help your program make decisions! 🤔
These comparisons return either true (1) or false (0).
📋 Common Relational Operators
==– Equal to!=– Not equal to>– Greater than<– Less than>=– Greater than or equal to<=– Less than or equal to
🧪 Example: Comparing Values
#include <iostream>
using namespace std;
int main() {
int a = 10;
int b = 20;
cout << "a == b: " << (a == b) << endl;
cout << "a != b: " << (a != b) << endl;
cout << "a > b: " << (a > b) << endl;
cout << "a < b: " << (a < b) << endl;
cout << "a >= b: " << (a >= b) << endl;
cout << "a <= b: " << (a <= b) << endl;
return 0;
}
💡 Real Use?
Relational operators are super useful in if-else conditions, loops, and anytime your program needs to make a decision. 🧠