From the course: Complete Guide to C Programming Foundations

Unlock the full course today

Join today to access over 24,800 courses taught by industry experts.

Understanding variable scope

Understanding variable scope

- [Instructor] A storage class sets a C language variable's scope. The scope defines the variable's availability to other functions in the source code file. Three keywords define the classes. An auto variable is local or private to the function in which it's defined. The value is released after the function quits. This is the default class. The keyword auto is optional when declaring a variable. Static variables are also local to their functions, but they retain their values after the function quits. An external variable exists outside of, or external to, a function. Its value is available to all functions. This type of variable is also known as a global variable. In this code, the variables A and B are local to the sum function. Their values are used in this function then discarded when the function is done. You can't see it in the output, but the values have been discarded when the function returned back to the main function. The construction at line five is a bit odd because it…

Contents