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?



Why for local variables the memory required to hold the variable is allocated from the program sta..

Answer / 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

More C++ General Interview Questions

What is a virtual destructor? Explain the use of it?

0 Answers  


What is fflush c++?

0 Answers  


Write a program to calculate the BMI of a person using the formula BMI = weight/height2.

2 Answers  


Explain what you mean by a pointer.

0 Answers   TCS,


Is c++ an integer?

0 Answers  






What are the uses of static class data?

0 Answers  


What is the benefit of learning c++?

0 Answers  


What are put and get pointers?

0 Answers  


When the constructor of a base class calls a virtual function, why doesn't the override function of the derived class gets called?

0 Answers  


How do you print for example the integers 3,2,1,5,4 in a binary tree within the console in format where it looks like an actual binary tree?

0 Answers  


What is linked list in c++?

0 Answers  


What is functions syntax in c++?

0 Answers  


Categories