+ 3

Is static variable is subset of global variable ?

What I have observe that global variable functionality is same as static and sometimes beyond it. So, why do we still use static keywords and make program more complex?

20th Jun 2023, 1:24 PM
Md Saif Ali
Md Saif Ali - avatar
2 Respostas
+ 4
Keywords global and static are not the same. Global declares global scope of visibility. Static declares storage class. The scope of a static depends on where and how it is declared. Storage class can be static, register, extern, or auto. Storage class is part of every type declaration, though if it is not declared, then the default is auto. Storage class specifies whether the item is persistent or temporary. It can be persistent (static) and not global.
20th Jun 2023, 2:51 PM
Brian
Brian - avatar
+ 1
Brian thanks for the clarification
21st Jun 2023, 5:46 AM
Md Saif Ali
Md Saif Ali - avatar