Arduino中的引用和解引用運算子


引用 (&) 和解引用 (*) 在 Arduino 中的運算子類似於 C。引用和解引用與指標一起使用。

  • 如果 x 是一個變數,那麼它的地址由&x表示。

  • 類似地,如果p是指標,那麼p指向的地址中包含的值由&p表示。

示例

void setup() {
   // put your setup code here, to run once:
   Serial.begin(9600);
   Serial.println();
   int x = 10;
   int *p;
   p = &x; //p now contains the address of x
   Serial.print("The value stored in the address pointed by p is: ");Serial.println(*p);
}

void loop() {
   // put your main code here, to run repeatedly:
}

輸出

序列監視器輸出 −

更新於:2021-08-02

2K+ 次瀏覽

開啟你的 職業生涯

完成課程獲得認證

開始
廣告