Well, what do you think?
Lets look at a very simple example:
Code:
int a;
int b;
int add() {
return a+b;
}
int main(void) {
a = 1;
b = 2;
printf("a+b=%d\n",add());
return 0;
}
Now, I have initialised two global variables here which both functions (main and add) can use. But what if I took them away and initialised them in main() ?
Code:
int add(int a, int b) {
return a+b;
}
int main(void) {
int a, b;
a = 1;
b = 2;
printf("a+b=%d\n",add(a,b));
return 0;
}
Here I initialise the variables in main() and pass them to the add function - add(int a, int b). I didn't need to do this before as they were declared globally. Do you understand?