Demonstration of the difference between global variables and local variables. - C Function

C examples for Function:Global Variable

Description

Demonstration of the difference between global variables and local variables.

Demo Code

#include <stdio.h>

int g1 = 10;//w  ww  .j  av  a  2  s  .co m
float g2 = 29.0;

void prAgain() {
   int l2 = 5;

   // Can't print l1--it is local to main
   printf("%d %.2f %d\n", l2, g2, g1);

   return;
}

int main() {
   float l1;

   l1 = 9.0;

   // prints the 1st global and first local variable
   printf("%d %.2f\n", g1, l1);

   prAgain(); // calls our first function

   return 0;
}

Related Tutorials