What exactly happens when pointers are assigned string values ​​during initialization?

I am very confused, because from what I learned, pointers store the addresses of the data they point to. But in some codes, I see strings often assigned to pointers during initialization.

What exactly is happening with the string?
Does the pointer indicate to automatically assign an address to store the string and point to this address?
How does dereferencing work in line pointers?

+4
source share
2 answers

Q: I see strings often assigned to pointers during initialization.

, , , .

C11, §6.4.5

- , , "xyz". [...]

"xyz" , , .

Q: ?

A: , . , , . , undefined .

Q: "" ?

A: , .

+4

char *p = "String";

"String", "String" p .

p --------------+
                |
                |
                V
             +------+------+------+------+------+------+------+
             |      |      |      |      |      |      |      |
             | 'S'  | 't'  | 'r'  | 'i'  | 'n'  | 'g'  | '\0' |
             |      |      |      |      |      |      |      |
             +------+------+------+------+------+------+------+
              x100    x101   x102   x103   x104   x105   x106
+8

Source: https://habr.com/ru/post/1617593/


All Articles