Loading...
Loading...
Loading Curriculum...
Loading Subject...
Loading Topic...
Loading Lesson...
Loading Lab...
Variables declared inside a function or a block are local to that context. They are created when the block is entered and destroyed when it is exited.
void func() {
int x = 10; // local to func
cout << x;
}
// x cannot be used here!Typically stored on the stack, making allocation and deallocation very fast.
Local variables aren't automatically initialized. They contain random "garbage" until assigned.
A local variable "shadows" or hides a global variable with the same name within its scope.