In this post, I am going to explain the global, static variables in C
********
main.c
********
int a[2]; // this is the non-static global variable, could be used at other files
int static b; // this is the static global variable, could only be used in this file
void main()
{
int static c; // this is the static variable like in java. associated with class.
// it only has one copy,
swap();
}
********
swap.c
********
extern int a[2];
void swap()
{
int tmp;
tmp = a[0];
a[0] = a[1];
a[1] = a[0]
}
deals please see slides 14
http://www.cs.gmu.edu/~setia/cs367/slides/index.html
No comments:
Post a Comment