What are the different data types?
Solidity is a statically typed language; the type of data a variable holds needs to be predefined. By default, all bits of the variables are assigned to 0. In Solidity, variables are function scoped; that is, a variable declared anywhere within a function will be in scope for the entire function regardless of where it is declared.
Now let's look at the various data types provided by Solidity:
- The most simple data type is
bool
. It can hold eithertrue
orfalse
. uint8
,uint16
,uint24
...uint256
are used to hold unsigned integers of 8 bits, 16 bits, 24 bits ... 256 bits, respectively. Similarly,int8
,int16
...int256
are used to hold signed integers of 8 bits, 16 bits ... 256 bits, respectively.uint
andint
are aliases foruint256
andint256
. Similar touint
andint
,ufixed
andfixed
represent fractional numbers.ufixed0x8
,ufixed0x16
...ufixed0x256
are used to hold unsigned fractional numbers of 8 bits, 16 bits ... 256 bits, respectively. Similarly,fixed0x8...