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 - C Tutorial
From the course: Complete Guide to C Programming Foundations
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
-
-
-
-
Understanding C language data types3m 17s
-
(Locked)
Declaring variables2m 53s
-
(Locked)
Working with variables3m 4s
-
(Locked)
Exploring the printf() function3m 48s
-
(Locked)
Using constants2m 58s
-
Challenge: Making variables and constants53s
-
(Locked)
Solution: Making variables and constants1m 16s
-
(Locked)
Understanding variable scope3m 35s
-
(Locked)
Making new data types3m 25s
-
(Locked)
Specifying characters and strings3m 17s
-
(Locked)
Specifying integers and real numbers3m 55s
-
(Locked)
Typecasting a variable2m 20s
-
(Locked)
Chapter challenge: Adding variables and constants1m 10s
-
(Locked)
Chapter solution: Adding variables and constants2m 7s
-
-
-
-
-
-
-
-
-
-