O'Reilly logo

SAMS Teach Yourself C++ in 10 Minutes SECOND EDITION by Jesse Liberty

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Heaps Versus Stacks

You might recall from the discussion of local variables and loops that the opening brace of a block is where variables defined inside the block are created and that the block's closing brace causes that storage to disappear. This is true for functions, loops, and if statements.

The storage for these variables is said to be “allocated on the stack.”

A stack is a common “array-like” data structure whose elements are added to one end (pushed) and then taken away from that same end (popped). The compiler generates code to expand and contract a program's single stack of storage each time you call or return from a function and each time you open or close a block.

Figure 13.1 shows what happens when you call the function UserWantsToContinueYorN() ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required