What is the difference between static structure and normal structure?

I have some sample code.

struct node { 
        int data;
        struct node *link;
    };
    static struct node *first = NULL;

It would be great if someone could talk about my bottom questions about using the word static.

  • What does the static keyword do in the above code?

  • What is the difference between normal structure and static structure?

+5
source share
5 answers

It creates a static pointer to nodeand initializes it to NULL.

A variable definition can have several values:

static struct node *first = NULL;

If defined outside the method, it gives an first internal binding . It can only be used inside the defining module.

But you can also find this line inside the method:

void foo()
{ 
    static struct node *first = NULL;
}

- , . NULL , .

+7

, .

. - ,

extern struct node *first;

, , first, ​​, .

+5

. , first .

+2

, . .

, .

0

static , ( ) 0, . static , ( , ).

, ​​, .

static , . - static , .

.

.

. , , .

, , . , , .

0

All Articles