static function in c language

Status
Not open for further replies.
I will quote you a simple example !

observe the code with and with out static,
Code:
#include<stido.h>
void foo(void)
{
    // int a = 10;
    static int a = 10;
    a++;
    printf("%d\n",a);
}

int main()
{
	foo();
    foo();
	
}
 

hi friend

I appreciate your previous work.but, my friend I would like to inform you that is static variable explanation. I knew it already. I want to know something about static function.

I have some basic idea about that function, i tried in my code blocks complier. the way of working is some what differ from what I knew the same.
 

When a function is declared as a Static function, it limits the scope of that function to the c file it is in.
So when a program is made up of several linked c files, the function can not be seen or called from the other c files.
So it is used to limit the scope of a function. (to avoid name clashes amongst other things)
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…