char

描述

資料型別 char 占用 1 個位元組的記憶體空間儲存一個字符值,將文字寫在單引號之中表示為字符,像是 ’A’ (若是多個字符則稱為字串並改用雙引號: ”ABC”)。

字元透過編碼成數字後以其數值儲存起來,字符的編碼方式請參見 ASCII 表,這代表使用字符的 ASCII 碼可以進行算術處理(例如 ’A’+1 的數值為 66,因為大寫字母 A 的 ASCII 碼是 65),關於更多的字元如何轉換為數字的資訊請參考 Serial.println

char 是一個帶有正負號的資料型別,這表示它的編碼範圍是從 -128 到 127,若是無符號的型別則為 1 個位元組大小 (8位元) 的資料型別。

範例

  char myChar = 'A';
  char myChar = 65;      // 兩者是相等的

See also

byte
int
array
Serial.println


語法參考主頁面

本頁由熱血青年 LBU 譯自英文版。

The text of the 86Duino reference is a modification of the Arduino reference, and is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.