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
What are the various oops concepts in c++?
What is the function to call to turn an ascii string into a long?
What are its advantages and disadvantages of multiple inheritances (virtual inheritance)?
Is python written in c or c++?
Define a pointer to a data member of the type pointer to pointer?
Why do we need templates?
What is Destructor in C++?
Why is c++ so fast?
What is the use of pointer in c++ with example?
Who made c++?
What is meant by a delegate?
What is iterator c++?
How do you initialize a string in c++?
Why is main function important?
Can java be faster than c++?