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 uses of static class data?
What is the difference between a type-specific template friend class and a general template friend class?
Why can’t you call invariants() as the first line of your constructor?
What is private public protected in c++?
What is struct c++?
Can a program run without main function?
What apps are written in c++?
What is a literal in c++?
What is flush programming?
If all is successful, what should main return a) 0 b) 1 c) void
Is it possible for the objects to read and write themselves?
Do class method definitions?
When should we use multiple inheritance?
Can I make ios apps with c++?
What is data abstraction? How is it different from data encapsulation?