章 10.各類運算符

目錄
算術運算符
指定變數的值
以位元為單位的運算符
用來作比較的運算符
統控錯誤的運算符
可執行命令的運算符
Incrementing/Decrementing 增值/損值運算符
邏輯類運算符
運算符的先後次序 (先乘除後加減的問題)
文句運算符

算術運算符

還記得中小學教的加減乘除嗎 ? 這些算符就是那樣用的。

表格 10-1.算術運算符

示範 算符名稱運算結果
$a + $b加法 Addition$a 、$b 的和
$a - $b 減法 Subtraction $a、 $b 的差
$a * $b 乘法 Multiplication $a 、$b 的積
$a / $b除法 Division$a 、$b 的商
$a % $b餘數 Modulus$a 除以 $b 後的餘數

The division operator ("/") returns an integer value (the result of an integer division) if the two operands are integers (or strings that get converted to integers) and the quotient is an integer. If either operand is a floating-point value, or the operation results in a non-integer value, a floating-point value is returned.