Go-arithmetic-operators
提供:Dev Guides
Go-算術演算子
次の表に、Go言語でサポートされているすべての算術演算子を示します。 変数 A が10を保持し、変数 B が20を保持すると仮定すると、
Operator | Description | Example |
---|---|---|
+ | Adds two operands | A + B gives 30 |
- | Subtracts second operand from the first | A - B gives -10 |
* | Multiplies both operands | A* B gives 200 |
/ | Divides the numerator by the denominator. | B/A gives 2 |
% | Modulus operator; gives the remainder after an integer division. | B % A gives 0 |
++ | Increment operator. It increases the integer value by one. | A++ gives 11 |
— | Decrement operator. It decreases the integer value by one. | A-- gives 9 |
例
Goプログラミング言語で使用可能なすべての算術演算子を理解するには、次の例を試してください-
上記のプログラムをコンパイルして実行すると、次の結果が生成されます-