Tuesday, 25 September 2012

Global Variables

Code:
#include<stdio.h>
static int anotherNum = 200;
int main()
{
    extern int anotherNum;
    printf("Value of anotherNum is %d\n", anotherNum);
    anotherNum += 50;
    printf("Value is now %d\n", anotherNum);
    extern int num;
    printf("Value of num is %d\n", num += 50);
    printf("Value of num is now %d", num);
    return 0;
}


From another file...
int num = 100;

Output:
Value of anotherNum is 200
Value is now 250
Value of num is 150
Value of num is now 150
 
I learned how to:
  • Create global variables and use them
  • Use global variables from another file
  •  
     
     

No comments:

Post a Comment