c语言关系运算符运算顺序
Relational operators are used to compare two operands; these are the binary operators that require two operands. These operators compare both operands and returns either 1 (true) or 0 (false).
关系运算符用于比较两个操作数。 这些是需要两个操作数的二进制运算符。 这些运算符比较两个操作数,并返回1 ( true )或0 ( false )。
关系运算符的类型 (Type of the relational operators)
The relational operators are,
关系运算符是
SNo. | Operator | Description | Example |
---|---|---|---|
1 | == | Equal To operator | x == y |
2 | != | Not Equal To operator | x != y |
3 | < | Less Than operator | x < y |
4 | <= | Less Than or Equal To operator | x <= y |
5 | > | Greater Than operator | x > y |
6 | >= | Greater Than or Equal To operator | x >= y |
编号 | 操作员 | 描述 | 例 |
---|---|---|---|
1个 | == | 等于运算符 | x == y |
2 | != | 不等于运算符 | x!= y |
3 | < | 少于运算符 | x <y |
4 | <= | 小于或等于运算符 | x <= y |
5 | > | 大于运算符 | x> y |
6 | > = | 大于或等于运算符 | x> = y |
1)等于运算符(==) (1) Equal To operator (==))
Equal To (==) operator compares both operands and returns 1 if both are the same; 0, otherwise.
等于(==)运算符比较两个操作数,如果两个相同,则返回1;否则,返回1。 0,否则。
Syntax:
句法:
operand1 == operand2
Example:
例:
// C++ program to demonstrate the
// example of == operator
#include <iostream>
using namespace std;
int main()
{
int x = 10;
int y = 10;
cout << "(x == y) : " << (x == y) << endl;
if (x == y)
cout << x << " is equal to " << y << endl;
else
cout << x << " is not equal to " << y << endl;
x = 20;
y = 30;
cout << "(x == y) : " << (x == y) << endl;
if (x == y)
cout << x << " is equal to " << y << endl;
else
cout << x << " is not equal to " << y << endl;
return 0;
}
Output:
输出:
(x == y) : 1
10 is equal to 10
(x == y) : 0
20 is not equal to 30