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 are protected members in c++?

0 Answers  


What is the first name of c++?

0 Answers  


Please explain class & object in c++?

0 Answers  


explain the reference variable in c++?

0 Answers  


Can member functions be private?

0 Answers  






What is the return value of the insertion operator?

0 Answers  


class Alpha { public: char data[10000]; Alpha(); ~Alpha(); }; class Beta { public: Beta() { n = 0; } void FillData(Alpha a); private: int n; }; How do you make the above sample code more efficient? a) If possible, make the constructor for Beta private to reduce the overhead of public constructors. b) Change the return type in FillData to int to negate the implicit return conversion from "int" to "void". c) Make the destructor for Alpha virtual. d) Make the constructor for Alpha virtual. e) Pass a const reference to Alpha in FillData

2 Answers   Quark,


Difference between Abstraction and encapsulation in C++?

0 Answers   Impetus,


Is there a datatype string in c++?How is the memory allocation?

3 Answers  


Why is that unsafe to deal locate the memory using free( ) if it has been allocated using new?

0 Answers  


How to construct virtual constructor

6 Answers   CIStems Software, Symphony,


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,


Categories