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操作员

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 ab = 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 satisfiedAND :应同时满足两个条件
  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 satisfiedOR | :至少应满足一个条件
  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运算符优先级

c运算符优先级_C运算符相关推荐

  1. C 运算符优先级——位运算符和逻辑运算符

    C 运算符优先级--位运算符和逻辑运算符   在进行C语言开发时,若单条表达式用到的运算符过多,需要注意运算符的优先级,否则无法得到欲得到的结果,最显而易见的便是"先算乘除,后算加减&quo ...

  2. c++运算符优先级_C语言入门教程-(6)运算符

    1.运算符概述 运算符是一种编译器执行特定的数学或逻辑操作的符号.C语言提供了以下类型的运算符: 算术运算符 关系运算符 逻辑运算符 位运算符 赋值运算符 条件运算符 其他运算符 2.算术运算符 算术 ...

  3. js运算符优先级和~~运算符

    下表按从最高到最低的优先级列出JavaScript运算符.具有相同优先级的运算符按从左至右的顺序求值. 运算符 描述 . [] () 字段访问.数组下标.函数调用以及表达式分组 ++ -- - ~ ! ...

  4. PHP排列运算符优先级,php运算符优先级顺序详解

    在我们前面讲PHP逻辑运算符的时候,提到了PHP运算符的优先级,所谓的运算符优先级,指的是在表达式中哪一个运算符先计算,哪一个后计算,就好像,表达式 1 + 5 * 3 的结果 是 16 而不是 18 ...

  5. 9、C语言中sscanf使用及运算符优先级

    1.sscanf()的使用技巧:<?xml:namespace prefix = o /> int sscanf(const char *buffer, const char *forma ...

  6. C语言重难点:运算符优先级

    文章目录 运算符优先级 算数运算符 关系运算符 逻辑运算符 位运算符(点击) 赋值运算符 其他 运算符优先级 括号等>负号.自增减.取地址.解引用.!.sizeof>乘除加减.移位> ...

  7. php中的逻辑运算符优先级,PHP运算符优先级 运算符分类

    运算符 运算符是可以通过给出的一或多个值(用编程行话来说,表达式)来产生另一个值(因而整个结构成为一个表达式)的东西. 运算符可按照其能接受几个值来分组.一元运算符只能接受一个值,例如 !(逻辑取反运 ...

  8. oracle 计算 符号优先级,oracle 表达式运算符优先级

    oracle 有以下几种运算符 算数运算符 连接运算符 比较(关系)运算符 逻辑运算符 1.算数运算符 算数运算符有四个, + , - ,* ,/. SELECT sal,sal*12 from em ...

  9. Java 运算符和Java运算符优先级

    Java 运算符和Java运算符优先级 Java 运算符 算术运算符 关系运算符 逻辑运算符 赋值运算符 条件运算符(?:) 位运算符 Java运算符优先级 Java 运算符 我们可以把运算符分成以下 ...

最新文章

  1. java jdk 8u111_8u111-jdk-alpine在java开发中的NullPointerException错误解决方案
  2. Linux之查找文件命令
  3. w10查询自己电脑ip
  4. (3.5)HarmonyOS鸿蒙多按钮点击事件
  5. usg6000v 无法ping通_柯美复印机网络打印无响应?无法打印、扫描?原来这里出了问题...
  6. 创建一个简单的ArcGIS Server ASP.NET网页
  7. Linux之HugePages快速配置
  8. buntu12.10 64位 + android-ndk-r9 编译ffmpeg遇到的问题
  9. .animate css,animate-css
  10. 阿里巴巴16字真言 | 管理者的基本要求是什么?
  11. 【LOJ#10027】魔板
  12. POJ3061尺取法
  13. 单片机STM32入门——(2)按键控制
  14. Nahimic应用程序初始化失败
  15. pyinstaller spec文件详解
  16. 计算机开机总要按f1键,详解Win7系统电脑开机需要按F1键才能启动的解决方法
  17. vins estimator ProjectionFactor (Td) factor
  18. 科技兴关,荣联与天津海关共建基因组数据库及分析平台
  19. 植物大战僵尸设计元素浅析
  20. [河北师范大学“云淮杯”][D]MJJ玩磁铁(Java)(贪心)

热门文章

  1. 大数据商业智能的十大戒律
  2. cocos2d怎么设置屏幕朝向?横屏 or 竖屏设置
  3. wireshark帮你解析网络包
  4. neo4j jdbc中文乱码
  5. spring学习笔记(六)
  6. Spring.NET学习笔记——目录(原)
  7. Asp.Net细节性问题精萃
  8. 使用Microsoft Lookback网卡解决了断网情况下 Virtual Server 虚机和主机的网络连接
  9. [转载] Python——函数练习(包括简单递归)
  10. 四边形不等式优化dp