C 中的数据类型是指用于声明不同类型的变量或函数的扩展系统。变量的类型决定了它在存储中占用的空间大小以及如何编译存储的位模式。
下面提供了在 Arduino 编程期间将使用的所有数据类型。

  • void
  • Boolean
  • char
  • Unsigned char
  • byte
  • int
  • Unsigned int
  • word
  • long
  • Unsigned long
  • short
  • float
  • double
  • array
  • String-char array
  • String-object

01_void

void 关键字仅在函数声明中使用。它表示该函数不会向调用它的函数返回任何信息。

  1. void Loop ( ) {
  2. // rest of the code
  3. }

02_Boolean(布尔值)

布尔值包含两个值之一,truefalse。每个布尔变量占用一个字节的内存。

  1. boolean val = false ; // 声明变量类型为 boolean 并初始化为 false
  2. boolean state = true ; // 声明变量类型为 boolean 并初始化为 true

03_char

占用存储字符值的一个字节内存的数据类型。字符文字用单引号写成:’A’;对于多个字符,字符串使用双引号- ABC
但是,字符存储为数字。你可以在 ASCII 图表中 看到特定的编码。这意味着可以对字符进行算术运算,其中使用字符的 ASCII 值。例如,’A’+ 1 的值为 66,因为大写字母 A 的 ASCII 值为 65。

  1. char chr_a = a ;//declaration of variable with type char and initialize it with character a
  2. char chr_c = 97 ;//declaration of variable with type char and initialize it with character 97

ASCII码表
image.png

04_unsigned char

unsigned char 是一种占用一个字节内存的无符号数据类型。 unsigned char 数据类型对 0 到 255 之间的数字进行编码。

  1. unsigned char chr_y = 121 ; // declaration of variable with type Unsigned char and initialize it with character y

05_byte

一个字节存储一个 8 位无符号数,从 0 到 255。

  1. byte m = 25 ;//declaration of variable with type byte and initialize it with 25