Addressing a string literal address in C

char **s = &"Is this valid?";

Does it get the address at which the address of the string literal is stored in C? I know that a string literal is stored in datasegment.rodata. However, getting the address of this address does not make sense.

It should be noted that gcc compiles this and creates a working executable.

+5
source share
2 answers

Your example is not valid:

char **s = &"Is this valid?";   // Not valid, wrong type

It's really:

char (*s)[15] = &"Is this valid?";  // OK

Type "Is this valid?"- char[15]. Array pointer type 15 of char- char (*)[15]. So the type &"Is this valid?"is equal char (*)[15].

Type of string literal char[N+1], where Nis the length of the string.

+7
source

Type &"Is this valid?"- char (*)[15](i.e. a pointer to an array of length -15 char).

, GCC , -Wall.

+2

All Articles