On Saturday, 16 March 2019 at 03:47:43 UTC, Murilo wrote:
Does anyone know if when I create a variable inside a scope as
in
{int a = 10;}
it disappears complete from the memory when the scope finishes?
Or does it remain in some part of the memory? I am thinking of
using scopes to make optimized programs that consume less
memory.
It depends on how the compiler translates and optimizes the code.
An integer variable like `a` in your example might never exist in
memory at all, if the compiler can allocate a register for it
until it goes out of scope. The easiest way to find out is to
look at a disassembly of the compiled code.