Rule 5

Assignments to state variable from another state variable always creates a new copy. Two value type state variables stateVar1 and stateVar2 are declared. Within the getUInt function, stateVar2 is assigned to stateVar1. At this stage, the values in both the variables are 40. The next line of code changes the value of stateVar2 to 50 and returns stateVar1. The returned value is 40 illustrating that each variable maintains its own independent value a shown in the following screenshot:

Two array type state variables, stateArray1 and stateArray2, are declared. Within the getUInt function, stateArray2 is assigned to stateArray1. At this stage, ...

Get Solidity Programming Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.