Why for local variables the memory required to hold the
variable is allocated from the program stack and for new
its allocated from the heap?

Answer Posted / achal ubbott

* Stack is a kind of data structure where Last In FirstOut
work. Local variables are needed for a short span of time
for immediate processing. So push and pop from stack is
used for them. Now memory is allocated to them in static
time only.

* new() operator allocates memory dynamically. Since
objects are needed for more time, space is taken from heap.

Is This Answer Correct ?    2 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is virtual base class?

567


What programming language should I learn first?

584


What is command line arguments in C++? What are its uses? Where we have to use this?

573


What are the effects after calling the delete this operator ?

553


What is prototype in c++ with example?

561






Can comments be longer than one line?

615


Write about the access privileges in c++ and also mention about its default access level?

615


What happens when you make call 'delete this;'?

603


What does the nocreate and noreplace flag ensure when they are used for opening a file?

676


Explain the extern storage classes in c++.

548


Is python better than c++?

584


Why is main an int?

524


Inline parameters : What does the compiler do with the parameters of inline function, that can be evaluated in runtime ?

2014


Which function should be used to free the memory allocated by calloc()?

587


Why should you learn c++?

579