How the computer handles variables

Seong-Am Kim
3 min readJun 25, 2020

I write down the code every day, but internally I didn’t know how the computer worked.

So I’m going to organize what I’ve studied about how computers handle variables.

Photo by Science in HD on Unsplash

Program memory address

In order for a program to run on a computer, the program must be loaded into memory. Therefore, the program must have enough memory space to cover its size.

A typical computer operating system manages memory space by dividing it into four categories

Global Variable

  1. Global variables are variables that are accessible anywhere in the program.
  2. The main functions is allocated to memory at the same time as the program starts even before it is excuted.
  3. The larger the program size, the more complex the program can be due to global variables.
  4. Loaded into the data area of memory.

Static variable

  1. Static variables are those that are accessible only in certain blocks.
  2. When the program runs, it is allocated to memory and released from memory where the program is terminated.
  3. Loaded into the data area of memory.

Local variable

  1. Local variables are those that can only be accessed from certain blocks in a program.
  2. Each time a function is executed, it is allocated to memory and released from memory when the function is terminated.
  3. It is recorded in the stack…
Seong-Am Kim