Course Content
C++ Intermediate | Mobile-Friendly
C++ Intermediate | Mobile-Friendly
Static Memory
Before we start studying the main purpose of pointers, we should understand what static and dynamic memory are.
- Static memory or Stack: Memory allocated for all your local variables and operations in your program (stack memory).
- Dynamic memory or Heap: An unused memory program in RAM that can be aplied for dynamic memory allocation.
Random access memory (RAM) is a computer's short-term memory for temporarily storing data that is currently in use. Let's go deep into it. Imagine that this is the area of our RAM:
As I've already told you, when we write a program, it knows how much memory space it will take up. We, for example, know that the variable type of int
needs 4 bytes.
This second small rectangle will be our program. It already allocates space in itself for all its static data: its variables and arrays in the form in which we declare them. When you and I declared a one-dimensional static array, we had to specify its length and pass the constant there or manually fill elements of the array that will be stored so that the compiler itself can calculate its length. That's exactly the main rule for static memory: We know how much memory we need.
Thanks for your feedback!