Search⌘ K
AI Features

Reference Types

Explore the distinction between value and reference types in Solidity, focusing on arrays as key reference types. Understand how memory, storage, and calldata affect data persistence and behavior within smart contracts to improve your Solidity programming skills.

An important distinction to note is that arrays, unlike the other types we've previously used, are classified as reference types. Since arrays are just the first example out of many reference types we'll learn in this course, it's important to understand the commonalities between all reference types since we'll start using them more and more as we progress.

We'll also learn about the differences between various data locations in smart contracts, an important topic that's a frequent source of confusion for new Solidity programmers.

Value types vs. reference types

In Solidity, types are divided into value types and reference types. So far in this course, all the variable types that we've been using have been value types. This includes uint, bool, address, etc.

What separates value types from reference types is that if we assign a value type to ...

Solidity
uint a = 1;
uint b = a;
b += 2; // This only changes the copy
// Variable "a" remains unchanged
...