Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there memory area called 'stack' in C++ to store automatic variables

Is there a specific area in memory called stack in C++ where automatic variables are getting stored.

like image 402
ajay Avatar asked Jan 14 '11 17:01

ajay


People also ask

Is stack memory automatic?

The allocation and deallocation for stack memory is automatically done. The variables allocated on the stack are called stack variables, or automatic variables.

Are variables stored in stack memory?

Whenever an object is created, it's always stored in the Heap space and stack memory contains the reference to it. Stack memory only contains local primitive variables and reference variables to objects in heap space.

How does C store variables in memory?

The static variables are stored in the data segment of the memory. The data segment is a part of the virtual address space of a program. All the static variables that do not have an explicit initialization or are initialized to zero are stored in the uninitialized data segment( also known as the BSS segment).

What is stack area in memory?

A stack is a special area of computer's memory which stores temporary variables created by a function. In stack, variables are declared, stored and initialized during runtime. It is a temporary storage memory.


1 Answers

No. The standard only mentions:

— static storage duration

— automatic storage duration

— dynamic storage duration

There is no such thing as 'stack memory' in C++. Yet it's common to say that the automatic storage duration variables are 'allocated on the stack' since it's the way it's implemented from computer science point of view. 'The heap' is another term that usually refers to dynamic storage duration but is not mentioned in the standard.

like image 113
Yakov Galka Avatar answered Oct 01 '22 12:10

Yakov Galka