What is the best way to initialize a pointer to a char array as mutable?

arrays, c, char

Solution

Assuming you have C99 features at your disposal, compound literals do the trick:

char *arr[] = { (char[]){"foo"}, (char[]){"bar"} };

Problem

It is clear that initializing a char array like ``` char* string = "foobar"; ``` will make it immutable. On the other hand, initializing a char array like ``` char string[] = "foobar"; ``` will be make it mutable. What is the best way to make a mutable initialization of pointer to a char array? ``` // member char arrays are immutable char* arr[] = {"foo", "bar"}; ```

Original source