+

名称

説明

加算は四則演算の一つである。演算子+(プラス)は、二つのオペランドの和を計算する。

書式

sum = operand1 + operand2;

引数

sum変数。利用できるデータ型: int, float, double, byte, short, long。
operand1変数か定数。利用できるデータ型: int, float, double, byte, short, long。
operand2変数か定数。利用できるデータ型: int, float, double, byte, short, long。

使用例

1
2
3
4
int a = 5;
int b = 10;
int c = 0;
c = a + b;  // the variable 'c' gets a value of 15 after this statement is executed

注意

  1. 加算演算子は、結果の型が格納可能な値よりも大きくなった時にオーバーフローする。 例えば、32767に1を加算すると、-32768になる。
  2. オペランドの一つがfloatかdoubleの場合は、浮動小数点計算が使われる。
  3. オペランドがfloatかdoubleで、加算の結果を格納する変数が整数型の場合、結果の整数部分だけが格納され、小数点以下は捨てられる。
1
2
3
4
float a = 5.5;
float b = 6.6;
int c = 0;
c = a + b;  // the variable 'c' stores a value of 12 only as opposed to the expected sum of 12.1

参照

オリジナルのページ

https://www.arduino.cc/reference/en/language/structure/arithmetic-operators/addition/

Last Revision: 2019/02/19

最終更新日

January 4, 2024

inserted by FC2 system