I have a Code example here.
struct node {
int data;
struct node *link;
};
static struct node *first = NULL;
It would be great if someone could throw some light on my below questions about the usage of the word static.
-
What does the keyword static do in the above code?
-
what is the difference between normal structure and static structure?
It creates a static pointer to a
nodeand initializez it toNULL.The variable definition can have multiple meanings:
If defined outside of a method, it gives
firstinternal linkage. It can only be used inside the defining module.But you can also find that line inside a method:
The variable is a method-scoped variable residing in static storage. It is initialized to
NULLonce and all subsequent changes persist between calls to the function.