Discussion in 'C' started by salonibhutani86, Sep 12, 2010.
what is the difference between stack mamory and heap memory?
Well, first of all, I think you should have googled it, and THEN, if you had any questions posted them here... but hey!
So, an object can have either automatic(stack) or dynamic(heap, or, more formally, free store) storage duration. There is also a third type of storage, that is, static storage, but I won't talk about it at the moment.
Any object created with 'new' is created on the heap, that means, its lifetime won't end until the program ends, or you explicitly call delete. On the other hand, any local object that was not created with 'new' is created on the stack, and its lifetime ends as soon as the control goes out of the block the variable was declared in.
Again, better google it
DiD you meant Heap and Free Store are same? I guess its not the same.
The C++ standard does not say anything about a 'stack' or a 'heap'. It operates with terms 'automatic' and 'dynamic'. The standard does not mandate how new be implemented, it only mandates the behaviour. There is a logical reason why automatic memory should be called a stack - that is because nested scopes are a stack in a sense. On the other hand I see no connection between a heap the data structure and a heap the memory. That's why I personally prefer the term free store. And yes, the free store and the heap is exactly the same thing in this context. Do you disagree?
Separate names with a comma.