i think there is issue with static variable with initialization because
Initialized are the ones that are given value from code at compile time. These are usually stored in DS though this is compiler specific.
The other type is uninitialized statics which are initialized at run time and are stored into BSS segment though again this is compiler specific
#include <stdio.h>
int* func()
{
static int a;
a = 5;
printf("%d\n",++a);
return &a;
}
int main(void)
{
int *b = func();
(*b)++;
func();
}
this code output is
6
6
but the difference is only with initialization
`static` means different things in different contexts.
1. You can declare a static variable in a C function. This variable is only visible in the function however it behaves like a global in that it is only initialized once and it retains its value. In this example, everytime you call `foo()` it will print an increasing number. The static variable is initialized only once.
void foo ()
{
static int i = 0;
printf("%d", i); i++
}
2. Another use of static is when you implement a function or global variable in a .c file but don't want its symbol to be visible outside of the `.obj` generated by the file. e.g.
static void foo() { ... }