Relational Operators
ใช้เปรียบเทียบค่าในตัวแปร 2 ตัว
| Operator | Description |
|---|---|
| > | Greater than |
| >= | Greater than or equal to |
| == | Is equal to |
| != | Is not equal to |
| <= | Less than or equal to |
| < | Less than |
ใช้ใน conditional statements และ loops
ตัวอย่าง
#include <iostream>
using namespace std;
int main() {
int a = 3, b = 2;
if (a < b) {
cout << a << " is less than " << b;
} else if (a > b) {
cout << a << " is greater than " << b;
} else if (a == b) {
cout << a << " is equal to " << b;
}
return 0;
}
ผลลัพธ์
3 is greater than 2
หมายเหตุ: เนื้อหานี้ทับซ้อนกับ ID 1004083487 มาก