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. JS 验证表单不能为空
  2. 同一服务器 数据库间 不同表 的查询
  3. 【PC工具】常用USB转串口芯片CP210x驱动,CH340G驱动安装有可能遇到的问题及解决办法...
  4. mybatis 动态SQL-foreach标签
  5. linux下rpm包安装jdk,linux jdk rpm包安装
  6. 安全可靠的透明加密软件
  7. 测量学8_大比例尺地形图测绘及地形图应用
  8. 一文带你揭秘并实现“大数据杀熟”背后的逻辑!
  9. 【管理经验】管理的本质-激发善意
  10. Python爬虫实战(一) QQ音乐评论爬取及可视化分析
  11. 计算机用户名英文名称,好听的电脑英文用户名
  12. 获取Windows操作系统版本和位数
  13. 蓝蓝算法04-字符串逆置
  14. 在mips64架构的国产系统中安装pyinstaller
  15. [分享] 【强烈推荐】要速度更要方便!75款实用Chrome插件推荐
  16. 二叉排序树实现英文文章单词统计
  17. 【云原生】这么火,你不来了解下?
  18. 可恶的as3.0,下载一个所谓的绿色flash cs5,竟然提示JAVA运行时环境初始化错误,请重新安flash
  19. 求1到50中7的倍数之和
  20. Java学习手册:Java是否支持多继承?为什么?

热门文章

  1. T1155 金明的预算方案 codevs
  2. SQL Server中的版本号
  3. %set rsh=server.CreateObject(adodb.recordset)%
  4. [转载] Python基本语法之:字符串和字典介绍
  5. [转载] C++转JAVA的转换方法及约定
  6. 微信小程序之 ----API接口
  7. 环境变量 - Maven
  8. 【Oracle】SQL语句优化
  9. Swift代码实现加载WEBVIEW
  10. ExtJS视频学习笔记