Rule 7

Assignments to memory variable from another state variable always creates a new copy. A value type state variable, stateVar is declared and initialized with value 20. Within the getUInt function a local variable of type uint is declared and initiated with value 40. The stateVar variable is assigned to the localVar variable. At this stage, the values in both the variables are 20. The next line of code changes the value of stateVar to 50 and returns localVar. The returned value is 20, illustrating that each variable maintains its own independent value as shown in the following screenshot:

A fixed array of uint stateArray is declared as ...

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.