* (dereference operator)

説明

アスタリスク演算子 * はポインタを扱うときに使用するC言語の演算子です。
pをアドレスとすれば、*pはpが指すアドレスに含まれる値を表します。

コード例

int *p;       // declare a pointer to an int data type
int i = 5;
int result = 0;
p = &i;       // now 'p' contains the address of 'i'
result = *p;  // 'result' gets the value at the address pointed by 'p'
              // i.e., it gets the value of 'i' which is 5

注意

ポインターは、C言語を学ぶ初心者にとって複雑なテーマの一つであり、Arduinoスケッチの大部分はポインターを使わずに書くことができます。しかし、特定のデータ構造を操作する際には、ポインタを使用することでコードを簡素化することができ、ポインタを操作するための知識は便利です。

タイトルとURLをコピーしました