Static Keyword ( C )
#include<stdio.h>
static int a;
int main(){
printf("%d \n",a); // will print 0
return (0);
}
#include<stdio.h>
void function(){
static int b=0;
b++;
printf("%d, ",b); // will print 1, 2, 3,
c++; //ERROR: 'c' was not declared in this scope
printf("%d, ",c); //ERROR: 'c' was not declared in this scope
}
int main(){
for(int i=0 ; i<3 ; i++){
function();
}
static int c=2;
c++;
printf("%d, ",c); //will print 3,
return (0);
}
// main.c
static func(){
return (0) ;
}
int func_1(){
return (10) ;
}
int main (){
printf("%d \n", func() ); //will print 0
printf("%d \n", func_1() ); //will print 10
printf("%d \n", func_2() ); // ERROR: Func_2() not declared in this scope.
printf("%d \n", func_3() ); // will print 20
return (0);
}
let's say, another file is also a part of the same project.
//file_1.c
static int func_2(){
return (10+func()); //ERROR: func() not declared in this scope.
}
int func_3(){
return (20);
}
Miscellaneous implications: