Here I have a basic doubt. Here it says that I need not to return global variables.
Now, I am wondering, if I return
a global variable (let it be char
or int
or some other data type), what horrid does it cause?
I know that, when I return
a variable from a function, the variable is destroyed immediately.
Does it mean, the memory allocated to that variable is de-allocated/freed?
Can someone please shed some light?
Consider the following code:
#include<stdio.h>
int var; //a global int
int MyFuction(void)
{
int temp_var = 0;
temp_var++;
return temp_var; //it will get destroyed after returning
}
int main(void)
{
MyFunction();
var++;
return var; //Will it get destroyed here, (var being a global variable)?
}