+ 10
What are the differences between normal variable and static variable in function concept?
4 Réponses
+ 1
I just try to give you an example.
void foo(int y)
{
int x = y;
}
When a block of program ie function ends the memory is automatically deallocated by compiler & that's why the variable x has no existence in our program.
But for static variable, the memory is not deallocated until the entire program ie main() ends.
+ 5
Normal variables are destroyed at the end of the function, because they are allocated on the stack.
Static variables aren't. They always exists, even after function call.
+ 1
Bibhash Ghosh It turned out that the question was posted a year ago. I perfectly understood the concept. Thanks sir.
0
Yeah I have noticed that after committing. Glad it helps.