Dynamic allocation/ Pointer to Pointer to update an Array containing parameter topicArray defined as follows:

const char* msgTopic = "Home/Messages";
const char* groupTopic = "Home/All";
char* deviceName = deviceTopic;
const char* topicArry[2] = {deviceTopic, groupTopic};


But deviceTopic can be changed during code run, and I wish that topicArray containg deviceTopic will have the correct value after deviceTopic has changed.

What is the right way doing so ?
You may try something like this:

const char* topicArry[2] = {NULL, groupTopic};
const char** const pDeviceTopic = &amp;topicArry[0];
#define deviceTopic (*pDeviceTopic)


Arguably not very elegant, but now when you assign, e.g.

deviceTopic = msgTopic;


you are actually writing into topicArry[0].