|
|
Diffenentiate between an internal static and external static variable? - C
|
Views : 253
|
|
Tagged in : C
|
|
|
Report This Scrap as Inappropriate We request you to choose the appropriate categroy and subcategory that suits your
objectionable concern about the scrap, So that our team can review and find out whether it violates our Guidelines or the
scrap is not suitable for all viewers.
|
An internal static variable is declared inside a block with static storage class whereas an external static variable is declared outside all the blocks in a file.An internal static variable has persistent storage,block scope and no linkage.An external static variable has permanent storage,file scope and internal linkage.
Internal static variable is block scope and persist there value between calls. External static variables are file scope. Normally when you need to declare global variable, it is good practices if you declare it as static for that particular file and provide interface function to access that global variable. This avoids accidentally modification of global variable.
e.g.
file 1
static int count;
int get_count()
{
return count;
}
void set_count(int cnt)
{
count = cnt;
}
so here other files can access count only by these functions. |
|
By Vijayaprasad, On - 2010-02-16 |
|
|
|