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 either true or false.
- 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 and int are aliases for uint256 and int256. Similar to uint and int, ufixed and fixed represent fractional numbers. ufixed0x8, ufixed0x16 ... ufixed0x256 are used to hold unsigned fractional numbers of 8 bits, 16 bits ... 256 bits, respectively. Similarly, fixed0x8, fixed0x16 ... fixed0x256 are used to hold signed fractional numbers of 8 bits, 16 bits ... 256 bits, respectively. If it's a number requiring more than 256 bits, then 256 bits data type is used, in which case the approximation of the number is stored.
- address is used to store up to a 20-byte value by assigning a hexadecimal literal. It is used to store Ethereum addresses. The address type exposes two properties: balance and send. balance is used to check the balance of the address and send is used to transfer Ether to the address. The send method takes the amount of wei that needs to be transferred and returns true or false depending on whether the transfer was successful or not. The wei is deducted from the contract that invokes the send method. You can use the 0x prefix in Solidity to assign a hexadecimal-encoded representation of values to variables.