Using literals
Solidity provides the use of literals for assignments to variables. Literals do not have names; they are the values themselves. Variables can change their values during program execution, but a literal retains the same value throughout. Take a look at the following examples of various literals:
- Examples of integer literals are
1
,10
,1
,000
,-1
, and-100
. - Examples of string literals are
"Ritesh"
and'Modi'
. String literals can be in single or double quotation marks. - Examples of address literals are
0xca35b7d915458ef540ade6068dfe2f44e8fa733c
and0x1111111111111111111111111111111111111111
. - Hexadecimal literals are prefixed with the
hex
keyword. An example of a hexadecimal literal ishex"1A2B3F"
.
Solidity supports decimal literals with the use of the aa dot – examples include 4.5
and 0.2
.
This concludes the details about declaring and using literal values within smart contracts. Now, it's time to move...