Preface
Solidity is a strongly-types language, that means every variable must be declared with its data type
Solidity language feature
Strongly type: The type of a variable cannot be changed after declaration
default value
A variable is automatically assigned a default value if not initialized.
The default value of an integer is 0, boolean is false, address is the zero address.
statement end symbol
Most statements must end with a semicolon
value types
these are the most basic data types in solidity
bool type
A boolean stores either true or false
Only lowercase are valid!
int/uint type
An int is a signed integer that can store positive and negative numbers.
An uint is an unsigned integer that can only store non-negative numbers.
you can specify the number of bits for an integer, from int8/uint8 to int256/uint256.
for example, uint8 uses 8 bits, while uint256 uses 256 bits.
if only int or unit is written, it defaults to int256 or uint256
address type
An address stores a 20-byte Ethereum address.
its default value is the zero address(0x00...00)
type compatible
an int32 cannot be assigned to an int8, but a smaller type can be implicitly assigned to a larger type. for instance: int8 can be assigned to int32
Top comments (0)