Size of a variable | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 11

Size of a variable

when I declare a variable it takes a part from the memory which memory they mean is it Ram or ssd or what (I am too ignorant 😓😭)

26th Aug 2018, 9:37 AM
ABADA S
ABADA S - avatar
5 Answers
+ 10
The stack is generally used to store all of the stuff you create at compile-time such as local variables, the parameters you pass in a function and more... The heap is mainly used to store all of the stuff you create at run time, there is always a variable that points to the dynamic space and this is what we call a "pointer". More: https://www.quora.com/What-is-the-difference-between-the-stack-and-the-heap
26th Aug 2018, 11:52 AM
Maz
Maz - avatar
+ 12
You're just a beginner, not ignorant, this is a legit question, LOL. Basically the allocated space depends on the variable itself, it can be stored mainly in CPU registers or into the stack. The stack is stored in computer RAM. CPU registers are way faster but limited. Note. There's also the heap where it's stored the dynamically created space, however the variable that points to that space is always located into the stack.
26th Aug 2018, 9:48 AM
Maz
Maz - avatar
+ 8
what is the defferent between stack and heap and what is the realtive between them and Ram
26th Aug 2018, 10:36 AM
ABADA S
ABADA S - avatar
+ 6
thanks for helping Maz
26th Aug 2018, 12:05 PM
ABADA S
ABADA S - avatar
+ 2
Java and JS =???
26th Aug 2018, 8:02 PM
Slavik Gorbunov
Slavik Gorbunov - avatar