Mega Code Archive

 
Categories / C / Language Basics
 

Define and use Global variables

#include <stdio.h> int count = 0;               /* Declare a global variable   */ /* Function prototypes */ void test1(void); void test2(void); void main() {    int count = 0;             /* This hides the global count */    for( ; count < 5; count++)    {      test1();      test2();    } } /* Function test1 using the global variable   */ void test1(void) {    printf("\ntest1   count = %d ", ++count); }  /* Function test2 using a static variable variable */ void test2(void) {    static int count;          /* This hides the global count */    printf("\ntest2   count = %d ", ++count); }