Search⌘ K
AI Features

Solidity Data Types: Complex Types

Explore complex data types in Solidity such as arrays, strings, bytes, structs, and mappings. Understand how these reference types store and manage data efficiently in smart contracts, enabling you to structure and access sophisticated data within your blockchain applications.

Complex types are combinations or variants of value types. They are also known as reference types because variables of these types don't directly store values but addresses (such as references) to the data they store.

Arrays: <type>[]

It's possible to arrange data of any type T in an array.

An array can have a fixed size k by declaring it with T[k], or a dynamic size by declaring it with T[].

We can also declare a multidimensional array, such as an array of arrays, using the syntax T[][]...[].

For instance, in the following contract, we declare a one-dimensional array of three booleans, a dynamic-sized array of addresses, and a dynamic-sized array of arrays that contain five unsigned integers each.

Solidity
pragma solidity >=0.5.0 <0.9.0;
contract exampleArrays {
bool[3] booleans=[true,false,true];
address[] addresses;
uint[5][] unsignedIntegers;
}

Just like in JavaScript, the indexes of Solidity arrays are zero ...