Data type stack
The stack data type is a fragment of RAM allocated for each data stream.
The stack works according to the LIFO principle. The essence of this principle is that the last piece of memory added to the stack will be the first to be removed from it.
The essence of working with a stack is that when a new variable is declared through a function, the first one is added to the stack. When the function finishes its work, the variable is automatically removed from the stack memory and the part it occupied becomes available to other objects.
The main advantage of the stack is the high speed of code execution, but the disadvantage is that when the memory allocated for the stack is full, the declared variables can no longer be changed and the code execution will stop. The stack size is set when the thread is created, and each variable has its own maximum memory size, which primarily depends on its data type. Because of this, it is necessary to declare the size of complex data types (for example, objects) in advance. Also, the stack can only hold local variables in memory; for global ones, a heap should be used.