Variable Types
Data types
Variables have a data type that determines the kind of value that can be stored in the variable. Solidity supports a variety of data types, including:
Boolean:
boolInteger:
intanduintof various sizesAddress:
addressBytes:
bytesandbyteString:
stringArrays:
arrayStructs:
structEnumerations:
enum
Default values
The concept of “undefined” or “null” values does not exist in Solidity. Newly declared variables (without assignment) always have a default value dependent on its type.
(u)int = 0
bool = False
string = ""
Data Location
Solidity variables can be classified according to their data location.
Value type
A value type stores its data directly in the memory it owns. Variables of this type are duplicated whenever they appear in functions or assignments. A value type will maintain an independent copy of any duplicated variables.
uint,int,address,bool,enum,bytes
Reference type
A reference type stores the address of the data’s location; acts as a pointer to a value stored elsewhere.
If you examine the location of where the reference type was created, it will contain the pointer directing us to the actual location of the value; not the value itself.
mapping,struct,arraystring arrays, byte arrays, array members, fixed/dynamic arrays
Last updated