Actions

EmSys

C - External variables

From EdWiki

External variables

  • If the variable is defined as a global variable, it can be accessed from any parts of the program, including the source files in which it is not defined.
  • If this global variable has to be accessed from some other source file(s), it has to be declared as external (extern) variable.
  • Example :
// File1.c
int nCounts = 0;
main()
{		
    nCounts = 100;
}		
 
// File2.c
extern int nCounts;
 
void TxData(void)
{		
    nCounts--;
}