Is it ok to return a reference of a function scope static variable?
- by kartik
I wanted to know if that has any ill effects under any circumsatnce.
For ex:
Ex1:
void* func1()
{
void* p_ref = NULL;
//function scope static variable
static int var1 = 2;
p_ref = &var1;
return p_ref;
}
Ex2:
//file scope static variable
static int var2 = 2;
void* func2()
{
void* p_ref = NULL;
var2 = 3;
p_ref = &var2;
return p_ref;
}
So in the above two cases what is the difference apart from the fact that var1 is function scope and var2 is file scope.
Thanks in advance.