An integer has fixed memory set at 4 bytes.
Hence, an integer can be directly stored within fixed memory, or on the stack.
A string does not have a pre-defined memory size, so it requires dynamic memory.
When a string object is created, the actual value is stored within dynamic memory, or on the heap.
To access it, a reference to this memory space is stored in the stack, thus the name "reference type".
Hence, an integer can be directly stored within fixed memory, or on the stack.
A string does not have a pre-defined memory size, so it requires dynamic memory.
When a string object is created, the actual value is stored within dynamic memory, or on the heap.
To access it, a reference to this memory space is stored in the stack, thus the name "reference type".