Created
September 20, 2012 21:21
-
-
Save only-entertainment/3758425 to your computer and use it in GitHub Desktop.
Example of global scope but bad usage
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
#include <stdio.h> | |
int foo(int, int, int, int, int, int); | |
// Globally scoped | |
int a, b, c = 0; | |
int x = 10; | |
int d, e = 0; | |
int main(int argc, char * argv[]) | |
{ | |
foo(a, b, c, x, d, e); | |
} | |
int foo(int aa, int bb, int cc, int xx, int dd, int ee) | |
{ | |
// Parameters are scoped to 'foo' | |
printf("Number: %d %d %d\n", aa, bb, cc); | |
scanf("%d %d %d", &aa, &bb, &cc); | |
dd = xx + aa + bb + cc; | |
ee = dd/4; | |
printf("Your number is: %d\n ", ee); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment