From the course: C Essential Training

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Understanding variable scope

Understanding variable scope - C Tutorial

From the course: C Essential Training

Start my 1-month free trial

Understanding variable scope

- [Instructor] A storage class sets a C language variable scope or its availability to functions in a source code file. Three key words define the classes. An auto variable is local or private to the function in which it's defined. This is a default class and the keyword auto is optional when declaring a variable. A static variable is similar to auto, but retains its value when the function quits. It too is local to the function in which it's defined. An extern variable exists outside of or external to a function, it's available to all functions. This type of variable is also known as a global variable. In this code, variables a and b are local to the sum function. Their values are used in this function then discarded when the function is done. Build and run to see how it works. And there's the output, nothing impressive. Still you've probably never seen a construction like the one shown here on line five. This is…

Contents