Last active
January 1, 2016 14:38
-
-
Save novnan/8158796 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 count; // this is a global variable | |
void head1(); | |
void head2(); | |
void head3(); | |
void main() | |
{ | |
int index; // this variable is available only in main | |
head1(); | |
head2(); | |
head3(); | |
// main "for" loop of this program | |
for(index = 8; index > 0; index--) | |
{ | |
int stuff; // this variable is only available in these braces | |
for(stuff = 0; stuff <= 6; stuff++) | |
{ | |
printf("%d", stuff); | |
} | |
printf("index is now %d\n", index); | |
} | |
} | |
int counter; //this is available from this point on | |
void head1() | |
{ | |
int index; // this variable is available only in head1 | |
index = 23; | |
printf("The header1 value is %d\n", index); | |
} | |
void head2() | |
{ | |
int count; //this variable is available only in head2 | |
// and it displaces the global of the same name | |
count = 53; | |
printf("The header2 value is %d\n", count); | |
} | |
void head3() | |
{ | |
printf("The header3 value is %d\n", counter); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment