arcollector
arcollector

Reputation: 109

static array of pointers vs non static array of pointers

What are the differences between adding and not adding the static keyword in the following array of pointers declaration.

static char *list[MAX] = {
        "Katrina",
        "Nigel",
        "Alistair",
        "Francesca",
        "Gustav"
    };

this declaration is located inside the main function

Upvotes: 0

Views: 135

Answers (2)

markgz
markgz

Reputation: 6266

Given that list is declared in the main function, it will be allocated on the stack unless the static keyword is used. In either case, the string literals will not be allocated on the stack.

Upvotes: 0

ouah
ouah

Reputation: 145839

With static the array of pointers will have static storage duration and without it will have automatic storage duration. In both cases the string literals pointed by the pointer elements of the array will have static storage duration.

Upvotes: 1

Related Questions