Previous: Chapter 14
Up: Chapter 14
Previous Page: Chapter 14
Next Page: 14.1 Storage Classes
In previous chapters we have discussed the declaration of variables within functions and described how memory space is allocated by the compiler for these variables as a program executes. How (and where) this memory is allocated, as well as how long it is allocated is determined by what is called the storage class for the variable. In addition we have discussed where within the code the variable name is ``visible'', i.e. where it can be accessed by name. This is called the scope of the variable. The variables we have seen so far have all been of storage class automatic, i.e. they are allocated when the function is called, and deallocated when it returns, with local scope, i.e. visible only within the body of the function. The C language provides several other storage classes together with their scope for controlling memory allocation. In this chapter we will discuss in more detail the concepts of memory allocation and present the other storage classes available in C, viz. automatic, external, register, and static. We will also see that functions, as well as variables, have storage class and scope. We next discuss dynamic allocation of memory, where a program can determine how much additional memory it needs as it executes. Finally, we introduce function pointers, i.e. pointer variables which can hold pointers to functions rather than data. We will see how these pointers are created, stored, passed as parameters, and accessed.