Link address to the first element of the array

I am a little confused by this:

I thought that if the pointer points to some object, the purpose of dereferencing some reference variable was a simple alias.

Example:

Object * p = &o;
Object & r = *p;
// r and o are the same object

I knew that there were some illegal cases, for example:

Object * p = NULL;
Object & r = *p; // illegal

Now, what about the code below?

const char * p = "some string";
const char & r = *p;

or

const char & r = *"some string";

I was told that this particular case concerns temporary objects, and therefore I could not get the address r and be sure that it would point to a memory array containing my starting line.

What does the C ++ standard mean in this case? Whether this is another illegal case, such as a NULL position, or behavior is allowed.

In other words, is it legal or illegal (undefined behavior?) To write something like?

   char buffer[100];
   strcpy(buffer, &r);
+5
source share
1

.

( ).

[C++11: 2.14.5/8]: UTF-8 . string literal "array of n const char`", n - , , (3.7).

[C++11: 3.7.1/1]: , , . (3.6.2, 3.6.3).

, ! , , .

+5

All Articles