Exercise 22. The Stack, Scope, and Globals
The concept of scope seems to confuse quite a few people when they first start programming. It originally came from the use of the system stack (which we lightly covered earlier), and how it was used to store temporary variables. In this exercise, we’ll learn about scope by learning how a stack data structure works, and then feeding that concept back in to how modern C does scoping.
The real purpose of this exercise, though, is to learn where the hell things live in C. When someone doesn’t grasp the concept of scope, it’s almost always a failure in understanding where variables are created, exist, and die. Once you know where things are, the concept of scope becomes easier.
This exercise will require ...