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 namespace std; and what is consists of?

0 Answers  


What is the object serialization?

0 Answers  


If you had the following code: int x = 23; int *y; y = &x; The instruction y++; does what?

2 Answers  


What is the first name of c++?

0 Answers  


founder of c++

7 Answers   Microtek, TCS, TeleCommand,






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

0 Answers  


Can a built-in function be recursive?

0 Answers  


why all c++ program must have default constructor?

6 Answers   IBM,


Why is polymorphism useful?

0 Answers  


How much do c++ programmers make?

0 Answers  


What is type of 'this' pointer? Explain when it is get created?

0 Answers  


Consider the following code fragment: int main(void) { int m = 4; mystery ( m ); mystery ( m ); printf("%d", m); return 0; } What is the output on the monitor if mystery is defined as follows ? void mystery (int m) { m = m+3; }

2 Answers   CDAC, Wipro,


Categories