-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e60eaa3
commit b39bf20
Showing
1 changed file
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
//global variable example | ||
|
||
#include <stdio.h> | ||
|
||
int fun1(void); | ||
int fun2(void); | ||
int fun3(void); | ||
|
||
int x ; /* global */ | ||
|
||
void main( ) | ||
{ | ||
x = 10 ; /* global x */ | ||
printf("x = %d\n", x); | ||
printf("x = %d\n", fun1()); | ||
printf("x = %d\n", fun2()); | ||
printf("x = %d\n", fun3()); | ||
} | ||
fun1(void) | ||
{ | ||
x = x + 10 ; | ||
} | ||
int fun2(void) | ||
{ | ||
int x ; /* local */ | ||
x = 1 ; | ||
return (x); | ||
} | ||
fun3(void) | ||
{ | ||
x = x + 10 ; /* global x */ | ||
} |