课程表

Arduino 基础

Arduino 函数库

Arduino 进阶

Arduino 项目

Arduino 传感器

Arduino 电机控制

Arduino 声音

工具箱
速查手册

Arduino 数据类型

当前位置:免费教程 » 程序设计 » Arduino

C中的数据类型是指用于声明不同类型的变量或函数的扩展系统。 变量的类型确定它在存储器中占用多少空间以及如何解释存储的位模式。


下表提供了您将在Arduino编程期间使用的所有数据类型。

voidBooleancharUnsigned char
byteintUnsigned int
word
longUnsigned long
shortfloatdoublearrayString-char array
String-object


void

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


例子

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


Boolean

布尔值保存两个值之一,true或false。 每个布尔变量占用一个字节的内存。


例子

  1. boolean val = false ; // declaration of variable with type boolean and initialize it with false
  2. boolean state = true ; // declaration of variable with type boolean and initialize it with false


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 Char Table


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


byte

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


例子

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


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)的范围。


例子

  1. int counter = 32 ;// declaration of variable with type int and initialize it with 32


Unsigned int

无符号整数(无符号整数)与存储2字节值的方式相同。 然而,它们不是存储负数,而是存储正值,产生0到65,535(2 ^ 16)-1的有用范围。 Due存储4字节(32位)值,范围从0到4,294,967,295(2 ^ 32-1)。


例子

  1. Unsigned int counter = 60 ; // declaration of variable with
  2. type unsigned int and initialize it with 60


Word

在Uno和其他基于ATMEGA的主板上,一个字存储一个16位无符号数。 在到期和零时,它存储一个32位无符号数。


例子

  1. word w = 1000 ;//declaration of variable with type word and initialize it with 1000


Long

长变量是用于数字存储的扩展大小变量,并存储32位(4字节),从2,147,483,648到2,147,483,647。


例子

  1. Long velocity = 102346 ;//declaration of variable with type Long and initialize it with 102346


unsigned long

无符号长变量是用于数字存储的扩展大小变量,并存储32位(4字节)。 与标准长整数不同,无符号整数不会存储负数,使得它们的范围为0到4,294,967,295(2 ^ 32 - 1)。


例子

  1. Unsigned Long velocity = 101006 ;// declaration of variable with
  2. type Unsigned Long and initialize it with 101006


short

short是16位数据类型。 在所有Arduinos(基于ATMega和ARM),一个短存储一个16位(2字节)的值。 这产生-32,768至32,767的范围(最小值为-2 ^ 15,最大值为(2 ^ 15)-1)。


例子

  1. short val = 13 ;//declaration of variable with type short and initialize it with 13


float

浮点数的数据类型是具有小数点的数字。 浮点数通常用于近似模拟值和连续值,因为它们的分辨率高于整数。


浮点数可以大到3.4028235E + 38,也可以低到3.4028235E + 38。 它们被存储为32位(4字节)的信息。


例子

  1. float num = 1.352;//declaration of variable with type float and initialize it with 1.352


double

在Uno和其他基于ATMEGA的主板上,双精度浮点数占用四个字节。 也就是说,double实现与float完全相同,精度没有增益。 在Arduino Due上,双精度具有8字节(64位)精度。


例子

  1. double num = 45.352 ;// declaration of variable with type double and initialize it with 45.352
转载本站内容时,请务必注明来自W3xue,违者必究。
 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号