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


Please Help Members By Posting Answers For Below Questions

Write a c program for binary addition of two 8 bit numbers.

3758


What do you understand by a pure virtual member function?

647


Is string an object in c++?

751


A company pays its salespeople on a commission basis. The salespeople receive $200 per week plus 9 percent of their gross sales for that week. For example, a saleperson who sells $5000 worth of merchandise in a week receives $200 plus 9 percent of $5000, or a total of $650. You have been supplied with a list of items sold by each salesperson. The values of these items are as follows: Item Value A 239.99 B 129.75 C 99.95 D 350.89 Write a program that inputs one salesperson's items sold in a week (how many of item A? of item B? etc.) and calculates and displays that salesperson's earnings for that week.

3517


What are friend functions in C++?

716






Why do we use pointers in c++?

680


What is the best c++ compiler for windows 10?

666


What are activex and ole?

655


What return value must conversion operators have in their declaration?

701


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

710


Which recursive sorting technique always makes recursive calls to sort subarrays that are about half size of the original array?

706


Why do we use setw in c++?

759


What is ios in c++?

750


What are features of c++?

742


What are the various compound assignment operators in c++?

628