c运算符优先级_C运算符

c运算符优先级

Operators are essential components in programming for logical and mathematical functions. Operators in C programming are categorized in the following ways.

运算符是逻辑和数学功能编程中必不可少的组成部分。 C编程中的运算符按以下方式分类。

C Operators

C Operators

C操作员

C中的算术运算符 (Arithmetic Operators in C)

二进制算术运算符 (Binary Arithmetic operators)

These are of 5 types.
We are assuming a=8 and b=2.

这些有5种类型。
我们假设a = 8b = 2

  1. Addition: ‘ +
    a + b
    //Answer: 10

    加法:“ +
  2. Subtraction: ‘
    a - b
    //Answer: 6

    减法:' '
  3. Multiplication: ‘ *
    a * b
    //Answer: 16

    乘法:' * '
  4. Division: ‘ /
    a / b
    //Answer: 4

    师:' / '
  5. Modulus : ‘ %
    a % b
    //Answer: 0 (Because reminder of  8/2 is 0)

    模量:' '

Note: The division operator gives quotient, while modulus operator gives reminder.

注意:除法运算符给出商,而模数运算符给出提醒。

一元算术运算符 (Unary Arithmetic operators)

These are of 2 types. These operators can be used before or after the operand.

这些有2种类型。 这些运算符可以在操作数之前或之后使用。

  1. Increment Operator ++ (Plus-Plus)

    增量运算符++ (Plus-Plus)
  2. It increments the value of given operand by 1.

    它将给定操作数的值加1。

    a = 10;
    a++; //incremented value by 1, a is now 11
    b=10;
    ++b; //incremented value by 1, b is now 11
  3. Decrement Operator – – (Minus-Minus)

    减量运算符– – (减号-减号)
  4. It decrements the value of given operand by 1

    将给定操作数的值减1

    a = 10;
    a--; //decremented value by 1, a is now 9
    b = 10;
    --b; //decremented value by 1, b is now 9

The above examples have used the post and pre increment/decrement operators in same way for the basic understanding. However, there is significant difference as well in particular scenarios which shall be discussed later.

上面的示例已使用post和pre递增/递减运算符进行基本了解。 但是,在某些特定情况下也存在重大差异,稍后将进行讨论。

C中的赋值运算符 (Assignment Operators in C)

They assign the value to the identifier on the left of operator from literal, another identifier or expression on right of operator.

它们的值分配给运营商的从操作者的右文字,另一标识符或表达左侧的标识符

  1. Assign: ‘ =
    a = 10; //assign value 10 to a
    b = a; //Assign value of a to b

    分配:“ =
  2. Perform Operation and Assign: +=   -=   *=   /=
    a = 5; //a has value 5
    a += 10; //is same as (a = a + 10) i.e. a = 5 + 10 which assigns value 15 to a
    
    b = 6; //b has value 6
    b -= 2; //is same as (b = b - 2) i.e. b = 6 - 2 which assigns value 4 to b

    执行操作并分配: + = -= * = / =

C中的关系运算符 (Relational Operators in C)

These are also called comparison operators, used to compare the values of two operands i.e. they tell whether the condition is true (1) or false (0).

这些也称为比较运算符,用于比较两个操作数的值,即它们告诉条件是true(1)还是false(0)。

  1. Less than <

    小于<
  2. Greater than >

    大于>
  3. Less than equal to <=

    小于等于<=
  4. Greater than equal to >=

    大于等于> =
  5. Equal equal to ==

    等于==
  6. Not equal to !=

    不等于!=
a = 10; //assign value 10 to a
a < 14; //is value of a less than 14 ? True. hence, result is 1
a >= 14; //is value of a greater than or equal to 14 ? False. hence, result is 0
a != 14; //is value of a not equal to 14 ? True. hence, result is 1
a == 14; //is value of a equal 14 ? False. hence, result is 0

Please Note that = is assignment operator, and == is comparison operator which checks whether values are equal or not.

请注意, =是赋值运算符,而==是比较运算符,它检查值是否相等。

C语言中的逻辑运算符 (Logical Operators in C)

These operators are used to make a decision by result of two or more conditions (relations).

这些运算符用于根据两个或多个条件(关系)的结果进行决策。

  1. AND & : Both conditions should be satisfied

    AND :应同时满足两个条件
  2. a = 10;
    a < 14 & a > 8; //a is less than 14 and a is greater than 8, hence result is 1 (true)
    a < 14 & a > 12; //a is less than 14 and a is not greater than 12 , hence result is 0 (false)
  3. OR | : at least one condition should be satisfied

    OR | :至少应满足一个条件
  4. b = 10;
    b < 14 | b > 12; //b is less than 14 or greater than 12, hence result is 1 (true)
    b > 14 | b < 8; //neither b is greater than 14, nor a is not less than 8 , hence result is 0 (false)
  5. Short Circuit AND &&

    短路AND &&
  6. Short Circuit OR ||

    短路或||
  7. These operators gives same output as their normal versions but they execute quicker.
    If AND operator finds false condition, it would not check the other condition since result would be false anyway. Similarly, if OR operator finds true condition, it won’t check other conditions.

    这些运算符的输出与正常版本相同,但执行速度更快。
    如果AND运算符发现错误条件,则不会检查其他条件,因为结果无论如何都是错误的。 同样,如果OR运算符找到真实条件,则不会检查其他条件。

  8. NOT ! : Reverse the Output

    :反转输出
  9. a = 5;
    (! a > 10); //True. a > 10 is false, but not operator is making it true, hence result is 1;

摘要 (Summary)

This is a basic introduction about operators and their usage. These are essential elements to get started with coding. In practice, there are several more operators in C programming for specific purposes which are not discussed at this point to keep things simple.

这是有关运算符及其用法的基本介绍。 这些是开始进行编码的基本要素。 在实践中,出于特定目的,在C编程中还有更多运算符,为使事情简单起见,此处不再讨论。

翻译自: https://www.journaldev.com/27602/operators-in-c

c运算符优先级

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值