BOOL foo(void){
static BOOL displayed = FALSE;
static BOOL initialized = FALSE;
if (displayed)
return FALSE;
//more code
displayed = TRUE;
return FALSE;
}
C中靜態局部變量的含義是什麼?C中靜態局部變量的含義是什麼?
如果第二次調用此方法,displayed
將不會重新初始化爲FALSE?
https://stackoverflow.com/questions/14992116/cc-the-purpose-of-static-const-local-variable – Brian
可能重複[什麼是靜態局部變量的用法,當我們可以得到一個全局變量在同樣的成本?](http://stackoverflow.com/questions/15808049/what-is-the-use-of-static-local-variable-when-we-can-get-a-global-variable-at -th) – Brian
如果第二次調用此方法,顯示將不會重新初始化爲FALSE? - 不,它會保留上次分配給它的值 –