Examples with global variables

The following code is split in two files. One file contains definitions of global variables. The other file uses some of them. Note that the "static" variable from fileOne.c is NOT the same as the "static" variable in fileTwo.c

/* fileOne.c: */

    int global     = 2;      // defines a global integer variable
    const int FOUR = 4;      // a constant variable (text segment)
    static int privat = 5;   // all functions in fileOne can use 
                             // Not visible outside of file

/* fileTwo.c: */

   extern int global;        // declares that fileTwo.c wants to use the 
                             // variable defined in fileOne.c
   static int private = 7;   // A new variable only visible within fileTwo.c

   void function(void)
          {
            int local = global * privat;  // local variable == 2*7
          }