C variable types and declarations
||This article needs more links to other articles to help integrate it into the encyclopedia. (March 2014)|
The C computer programming language has two variable types that must be declared before they are used.
The scope of a local variable is confined within the block or function where it is defined. Local variables must always be defined at the top of a block. When a local variable is defined it is not initialized by the system and must be initialized by the program. When execution of the block starts the variable is available, and when the block ends the variable 'dies'.
A global variable is defined at the top of the program file and it can be visible and modified by any function that may reference it. Global variables are initialized automatically by the system when you define them:
|Data Type||Initial value|
If the same variable name is being used for both a global and a local variable, then local variable takes preference in its scope. But it is not a good practice to use global variables and local variables with the same name.