Programming Operators and Expressions | 编程运算符与表达式

📚 Programming Operators and Expressions | 编程运算符与表达式

In Edexcel A-Level Computer Science, programming questions often depend on your ability to read, write and evaluate expressions built from operators. Understanding how arithmetic, comparison, Boolean and assignment operators behave is essential for tracing algorithms and writing correct pseudocode.

在 Edexcel A-Level 计算机科学中,编程题往往取决于你能否阅读、编写和计算由运算符构成的表达式。理解算术、比较、布尔和赋值运算符的行为对于追踪算法和写出正确的伪代码至关重要。


1. What Are Operators? | 什么是运算符?

An operator is a symbol or keyword that performs an operation on one or more operands. For example, in 5 + 3, the plus sign is an operator and 5 and 3 are operands.

运算符是对一个或多个操作数执行操作的符号或关键字。例如,在 5 + 3 中,加号是运算符,5 和 3 是操作数。

Operators allow programmers to combine values, compare them, make decisions and manipulate data within expressions.

运算符使程序员能够在表达式中组合数值、进行比较、做出判断和处理数据。


2. Arithmetic Operators | 算术运算符

The basic arithmetic operators are addition (+), subtraction (−), multiplication (*), division (/), integer division (DIV) and modulus (MOD). Most languages use * for multiplication and / for real division.

基本算术运算符包括加号(+)、减号(−)、乘号(*)、除法(/)、整数除法(DIV)和取模(MOD)。大多数语言用 * 表示乘法,用 / 表示实数除法。

Operator Meaning Example Result
+ Addition 7 + 2 9
Subtraction 7 − 2 5
* Multiplication 7 * 2 14
/ Real division 7 / 2 3.5
DIV Integer division 7 DIV 2 3
MOD Remainder 7 MOD 2 1

The table above gives the common arithmetic operations. Edexcel pseudocode uses DIV and MOD to handle integer division and remainders.

上表列出了常见的算术运算。Edexcel 伪代码使用 DIV 和 MOD 处理整数除法和余数。


3. Integer Division and Modulus | 整数除法与取模运算

DIV gives the whole-number part of a division, discarding any remainder. MOD gives only the remainder after whole-number division.

DIV 给出除法的整数部分,舍弃任何余数。MOD 只给出整数除法后的余数。

17 DIV 5 = 3 and 17 MOD 5 = 2 because 17 = 5 × 3 + 2

These operations are very common in exam questions about parity, digit extraction and circular indexing. For example, n MOD 2 = 0 checks whether n is even.

这些运算在关于奇偶判断、取位和循环索引的问题中非常常见。例如,n MOD 2 = 0 可以判断 n 是否为偶数。


4. Comparison Operators | 比较运算符

Comparison operators compare two values and return a Boolean result: TRUE or FALSE. The common ones are = (equal to), ≠ (not equal to), < (less than), > (greater than), ≤ (less than or equal to) and ≥ (greater than or equal to).

比较运算符比较两个值并返回布尔结果:TRUE 或 FALSE。常用的有 =(等于)、≠(不等于)、<(小于)、>(大于)、≤(小于等于)和 ≥(大于等于)。

In Edexcel pseudocode, the not-equal sign is often written as <> or ≠. Some languages use != instead.

在 Edexcel 伪代码中,不等号常写作 <> 或 ≠。有些语言使用 !=。

Operator Meaning Example that returns TRUE
= equal to 4 = 4
≠ or <> not equal to 4 ≠ 5
< less than 3 < 8
> greater than 9 > 2
less than or equal to 5 ≤ 5
greater than or equal to 7 ≥ 6

5. Boolean Operators | 布尔逻辑运算符

Boolean operators combine Boolean values. The three fundamental operations are AND, OR and NOT. AND returns TRUE only when both operands are TRUE; OR returns TRUE when at least one operand is TRUE; NOT reverses a single Boolean value.

布尔运算符用于组合布尔值。三种基本运算是 AND、OR 和 NOT。AND 仅在两个操作数都为 TRUE 时返回 TRUE;OR 在至少一个操作数为 TRUE 时返回 TRUE;NOT 对单一布尔值取反。

Truth tables are essential for tracing conditions. For example, (age

Published by TutorHao | A-Level 编程 Revision Series | aleveler.com

更多咨询请联系16621398022(同微信)

Comments

屏轩国际教育cambridge primary/secondary checkpoint, cat4, ukiset,ukcat,igcse,alevel,PAT,STEP,MAT, ibdp,ap,ssat,sat,sat2课程辅导,国外大学本科硕士研究生博士课程论文辅导Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from aleveler.com

Subscribe now to keep reading and get access to the full archive.

Continue reading

Exit mobile version