📅  最后修改于: 2020-11-04 04:20:43             🧑  作者: Mango
用任何语言编写程序时,您需要使用各种变量来存储各种信息。变量不过是用于存储值的保留内存位置。这意味着当您创建变量时,会在内存中保留一些空间。
您可能希望存储各种数据类型的信息,例如字符,宽字符,整数,浮点数,double浮点数,boolean等。操作系统根据变量的数据类型分配内存,并确定可以存储在变量中的内容。保留的内存。
Solidity为程序员提供了丰富的内置以及用户定义的数据类型。下表列出了七种基本的C++数据类型-
Type | Keyword | Values |
---|---|---|
Boolean | bool | true/false |
Integer | int/uint | Signed and unsigned integers of varying sizes. |
Integer | int8 to int256 | Signed int from 8 bits to 256 bits. int256 is same as int. |
Integer | uint8 to uint256 | Unsigned int from 8 bits to 256 bits. uint256 is same as uint. |
Fixed Point Numbers | fixed/unfixed | Signed and unsigned fixed point numbers of varying sizes. |
Fixed Point Numbers | fixed/unfixed | Signed and unsigned fixed point numbers of varying sizes. |
Fixed Point Numbers | fixedMxN | Signed fixed point number where M represents number of bits taken by type and N represents the decimal points. M should be divisible by 8 and goes from 8 to 256. N can be from 0 to 80. fixed is same as fixed128x18. |
Fixed Point Numbers | ufixedMxN | Unsigned fixed point number where M represents number of bits taken by type and N represents the decimal points. M should be divisible by 8 and goes from 8 to 256. N can be from 0 to 80. ufixed is same as ufixed128x18. |
address保存20字节的值,代表以太坊地址的大小。一个地址可以使用.balance方法获取余额,也可以使用.transfer方法将余额转移到另一个地址。
address x = 0x212;
address myAddress = this;
if (x.balance < 10 && myAddress.balance >= 10) x.transfer(10);