Briefly summarize the differences among static variables sta
Solution
Static variables:
These are variables that are created explicitly as static whose memory gets allocated once with a lifetime that is all through the runtime of the program.
Example:
Stack Variables:
Stack variables are those that get created when a function runs and then gets deallocated when the function ends. They dont use different memory space. It\'s same memory space, but different stack frame in this space.
Example:
heap-dynamic variables:
Variables that are created using new operator and pointers become heap variables. These variables should be explicitly deleted using delete operator. Their control is mostly with the programmer than the compiler.
Example:
#include <iostream>
int main()
{
int *pointer = new int[2]; //allocation
delete pointer; //deallocation
}
