/

[Arithmetic Operators]

説明

除算は四則演算の一つです。/(スラッシュ)演算子は2つのオペランドを演算して結果を生成します。

構文

result = numerator / denominator;

媒介変数

result: 変数。許可されるデータ型: intfloatdoublebyteshortlong.
numerator: 変数または定数。許可されるデータ型: intfloatdoublebyteshortlong.
denominatornon zero 変数または定数。許可されるデータ型: intfloatdoublebyteshortlong.

int a = 50;
int b = 10;
int c = 0;
c = a / b;  // the variable 'c' gets a value of 5 after this statement is executed

ヒント

  1. 数値 (オペランド) の 1 つが float 型または double 型の場合、計算には浮動小数点演算が使用されます。
  2. オペランドが float / double データ型で、結果を格納する変数が整数の場合、整数部分のみが格納され、数値の小数部分は失われます。
float a = 55.5;
float b = 6.6;
int c = 0;
c = a / b;  // the variable 'c' stores a value of 8 only as opposed to the expected result of 8.409

Language Reference Home

86Duinoリファレンスのテキストは、Arduinoリファレンスを改変したもので、Creative Commons Attribution-ShareAlike 3.0ライセンスに基づいてライセンスされています。リファレンス内のコードサンプルはパブリックドメインとして公開されています。

上部へスクロール