c语言关系运算符运算顺序_C / C ++中的关系运算符

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

2)不等于运算符(!=)

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值