answersLogoWhite

0


Best Answer

Call-stacks are fixed-length and are allocated on a per-thread basis as threads are instantiated. The stack pointer CPU register keeps track of the next available address in the current thread's stack. The compiler computes the length of a function according to the number and type of its local variables (including formal arguments) plus the return address. When the function is invoked, the current stack pointer is adjusted by this amount, creating a "stack frame" specific to that function. Given the start address of the stack frame, the local variables and formal arguments can be referred to via constant offsets within the stack frame. When the function returns, the stack pointer is readjusted, effectively freeing the memory without actually releasing it back to the system. In this way, memory can be allocated and released on the stack with minimum cost.

User Avatar

Wiki User

7y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How primitive variables are stored on Stack?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Where does Local Variables get stored in?

Stack.


Local Variables will get stored in?

Stack.


Where auto variables are stored?

Auto variables are stored on the stack alongside all other local variables.


Where local variables are stored in c?

On the stack.


Where do register variables get stored?

Either in registers or on the stack.


Can variables be changed?

A static variable is one which is not stored on the stack but in the memory of the program. Static variables can be changed.


Local Variables is stored in which part of the memory?

RAM = Random Access Memory


Where static variables stored?

they are stored in the memory.they obviously can't be stored in stack Bcoz there value won't be retained between function call.


What are primitive variables?

Primitive variables are variables that are not objects and carry primitive values like numbers, boolean etc. The primitive data types in java are:intbytefloatcharlongbooleanshortdouble


Where the local variables will be stored?

When you declare a variable and it's data type in a function, it is stored in the specific space for memory allocated by the variable type identifier known as the "stack."


What is the storage allocation and scope of global extern static local and register variables?

AnswerLocal Variables are stored in Stack. Register variables are stored in Register. Global variables are stored in data segment. The memory created dynamically are stored in Heap And the C program instructions get stored in code segment and the extern variables also stored in data segment. Nooo NoooStatic variable will be stored in .BSS segment... (Block Started By Symbol)


Where are the auto variable stored?

In procedural programming languages like C auto variables have a lifetime bound to their scope inside a function, and is often synonymous with local variable. They're commonly allocated in the current stack frame along with a function's arguments and a possible return value.