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

Write a C/C++ program that connects to a MySQL server and checks if the InnoDB plug-in is installed on it. If so, your program should print the total number of disk writes by MySQL.

4 Answers   Webyog,


What is the average salary of a c++ programmer?

0 Answers  


What are inline functions? What is the syntax for defining an inline function?

0 Answers  


class base { public: int fun(int) {} }; class base2 { public: int fun(float) { } }; so here qustion is both function either function overloading or over riding;

4 Answers   Manhattan,


What is the use of map in c++?

0 Answers  






Live example for static function?

1 Answers   Infosys,


What is encapsulation in C++? Give an example.

0 Answers   HAL, Honeywell, Zomato,


Which format specifier is used for printing a pointer value?

0 Answers  


What is the difference between an external iterator and an internal iterator?

0 Answers  


What is searching?

0 Answers  


Differentiate between a pointer and a reference with respect to c++.

0 Answers  


What are the advantages of c++ over c?

0 Answers  


Categories