Solidity Type Deduction
Solidity Type Deduction Main Tips
- For reasons concerning convenience, explicitly specifying the type of a variable is not necessary.
- If no particular type is referred to, the compiler sets it automatically.
Solidity Type Deduction
For reasons concerning convenience, explicitly specifying the type of a variable is not necessary.
If no particular type is referred to, the compiler sets it automatically. This is done based on the type of the first expression that has been assigned to the variable, like in the example below:
In this case, the type of variable x is going to be uint24. However, var cannot be used for declaring return or function parameters.
Warning: The type only gets deduced from the very first assignment, therefore loop in the code example here is infinite, since variable i will has the type uint8 and the greatest value of this type is not bigger than 2000 : for (var i = 0; i < 2000; i++) { . . . } .