COMP 206 Lecture Notes - Lecture 12: Global Variable, Local Variable, Equals Sign
Document Summary
See the updated version of the built in data types table below. C has been updated many times, so in 5 years, these values will likely not still be valid! Variables are usually declared 1) outside functions or 2) inside functions. The placement of the declaration determines scope: variables declared outside functions are called global variables. They have scope throughout the program: variables declared inside functions are called local variables. These mask global variables but only have local scope (only exist within the function in which they are declared) Note: if you redeclare a global variable in the local sphere, the local variable will take precedent. In general, you should stay away from these practices when coding because it is confusing and may cause the output to be different that you would like. Static keyword: allows a local variable to act like a global variable. In c, you can have separate declaration from implementation.