Solidity Data Types: Primitive Types
Learn the different primitive data types for variable declarations in Solidity.
The value of any Solidity variable, including local variables and function arguments, is visible to all blockchain observers. Reading the value of a variable does not cost anything, but modifying its value costs gas.
Solidity is a statically typed language, meaning that variable types have to be explicitly declared. All variables have a default value depending on their type. They can't be empty undefined.
Solidity variables can be of primitive types or complex types.
Note: Primitive types are always passed by value when used as function arguments or in an assignment, whereas complex types are passed by reference.
Primitive types are the simplest data types in Solidity. They're also known as value types because variables of this type directly store their value in a dedicated area of memory.
Signed integers: int
A signed integer variable can store positive or negative integer values. It's declared with the keyword int
.
For instance, the following contract creates the signed integer variable k
, initialized with a value of -1
.
Get hands-on with 1200+ tech skills courses.