Arduino - 数据类型.pdfVIP

  • 14
  • 0
  • 约2.87千字
  • 约 5页
  • 2017-08-22 发布于浙江
  • 举报
Arduino - 数据类型

Arduino - 数据类型 C 中的数据类型是指⽤于声明不同类型的变量或函数的扩展系统。 变量的类型确定它 在存储器中占⽤ 少空间以及如何解释存储的位模式。 下表提供了您将在Arduino编程期间使⽤的所有数据类型。 void Boolean char Unsigned char byte int Unsigned int word long Unsigned long short float double array String-char array String-object void void关键字仅⽤于函数声明。 它表⽰该函数预计不会向调⽤它的函数返回任何信息。 例⼦ Void Loop ( ) { // rest of the code } Boolean 布尔值保存两个值之⼀,true或false 。 每个布尔变量占⽤⼀个字节的内存。 例⼦ boolean val = false ; // declaration of variable with type boolean boolean state = true ; // declaration of variable with type boolea Char ⼀种数据类型,占⽤存储字符值的⼀个字节的内存。 字符⽂字⽤单引号写成:\A\ ,对 于 个字符,字符串使⽤双引号:“ABC 。 但是,字符存储为数字。 您可以在 ASCII 图表中查看特定编码。 这意味着可以对字 符进⾏算术运算,其中使⽤字符的ASCII值。 例如,\A\+ 1的值为66 ,因为⼤写字母 A的ASCII值为65 。 例⼦ Char chr a = ‘a’ ;//declaration of variable with type char and ini Char chr c = 97 ;//declaration of variable with type char and init unsigned char ⽆符号字符是⼀种⽆符号数据类型,占⽤⼀个字节的内存。 unsigned char数据类型对0 到255之间的数字进⾏编码。 例⼦ Unsigned Char chr y = 121 ; // declaration of variable with type U byte ⼀个字节存储⼀个8位⽆符号数,从0到255 。 例⼦ byte m = 25 ;//declaration of variable with type byte and initiali int 整数是数字存储的主数据类型。 int存储16位(2字节)值。 这产⽣-32,768⾄32,767的范 围(最⼩值为-2 ^ 15 ,最⼤值为(2 ^ 15)-1) 。 int ⼤⼩因板⽽异。 例如,在Arduino Due 中, int 存储32位(4字节)值。 这产 ⽣-2,147 ,483,648⾄2,147 ,483,647(最⼩值-2 ^ 31和最⼤值(2 ^ 31)-1)的范围。 例⼦ int counter = 32 ;// declaration of variable with type int and ini Unsigned int ⽆符号整数(⽆符号整数)与存储2字节值的⽅式相同。 然⽽,它们不是存储负数,⽽ 是存储正值,产⽣0到65,535(2 ^ 16)-1的有⽤范围。 Due存储4字节(32位)值,范围从0 到4 ,294 ,967 ,295(2 ^ 32-1) 。 例⼦ Unsigned int counter = 60 ; // declaration of variable with type unsigned int and initialize it with 60 Word 在Uno和其他基于ATMEGA的主板上,⼀个字存储⼀个16位⽆符号数。 在到期和零 时,它存储⼀个32位⽆符号数。 例⼦ word w = 1000 ;//declaration of variable with type word and initia Long 长变量是⽤于数字存储的扩展⼤⼩变量,并存储32位(4字节) ,从2,147 ,483,648到 2,147 ,483,647 。 例⼦ Long velocity = 102346 ;//declaration of variable with type Long a unsigned

文档评论(0)

1亿VIP精品文档

相关文档