0

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

arcollector
  • 101
  • 5

2 Answers2

1

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.

ouah
  • 142,963
  • 15
  • 272
  • 331
0

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.

markgz
  • 6,054
  • 1
  • 19
  • 41