A variable could contain data values which are “fixed”, but usually variables are used to contain/point to values that are dynamic.
Some formal programming languages also defines variables as Global variables or Local variables.
When a programmer runs a script containing variable declarations, the variable names will reserves one or more addresses in the Random Access Memory (RAM) where a binary value can be stored.
RAM has two different locations (Heap and Stack) where variable declarations can affect.
- Global variables usually go to the Heap.
- Local variables usually go in the Stack.
If you carry on to diploma and university studies, there will usually be a few foundational modules to help you better understand the theory linkage between programming and the compute systems. The learning topics will usually be named as Object-Oriented Programming, Data Structures and Algorithm, Flow Controls etc.
References:
- University of Illinois Urbana-Champaign. The Grainger College of Engineering. CS 225. Introduction to Data Structures and Algorithms with C++. Stack and Heap Memory. by Jenny Chen, Ruohao Guo. Ref: https://courses.engr.illinois.edu/cs225/fa2022/resources/stack-heap/
- Geeks for Geeks. Stack vs Heap Memory Allocation. Ankit Bisht. Ref: https://www.geeksforgeeks.org/stack-vs-heap-memory-allocation/
- Baeldung. What and Where Are the Memory Stack and Heap. Georgios Nanos. Ref: https://www.baeldung.com/cs/memory-stack-vs-heap
