What are the difference between static and extern variable?



Suraj Said

+0 -0

static variables are initialized only once, when they are first defined, and retain their value between function calls. They have a file scope, meaning they can be accessed by any function within the same file. And they are only visible within the file where they are defined.
extern variables are used to declare a variable that is defined in another source file. It tells the compiler that the variable has been defined elsewhere, and it should not allocate memory for the variable. It can be used to share variables across multiple files.



Submit Your Response