We've already covered how value types differ from reference types. Now, let's examine why they behave differently.
When storing new instances of a type in memory, Swift has two different data structures that it can use for storage: the Stack and the Heap. These structures are common to many programming languages. Value types are stored on the Stack, and reference types are stored on the Heap. Understanding how data is stored in these structures, even at the superficial level that we will cover, will help us to understand why value types and reference types have differing behaviors.
The stack can be thought of as sequential blocks of data. An instance of a type may be represented by multiple blocks of data, and an instance can be referenced using the memory position of its first piece of data. A Stack Pointer, which is a reference to the memory position at the end of the stack, is maintained. New instances are always added to the end of the stack...