There is no single assignment of A
possible that meets your requirements, since there are two assignments necessary;
- Initialise
A
so its value is the address of a valid char *
- Initialise that
char *
to point to the (first character of) an array of char
that contains a nul terminated string.
For example, assuming B
is a static
std::string B;
void some_func()
{
char some_thing[] = "abcdefg";
char *p = some_thing; // same effect as A[0] = some_thing or as *a = some_thing
char **A = &p;
B = A[0]; // note the assignment COPIES some_thing
// p and some_thing both cease to exist as function returns
// that is OK as B contains a copy of some_string
}
Note that I've carefully constructed this to work, as per your requirement. However, what you are trying to do is error prone (e.g. very easy to misuse any of the pointers in a way that causes undefined behaviour) so is generally considered poor practice in C++.