p will point to a read-only memory area that will be allocated on the stack. In addition, the compiler will automatically terminate the zero of the line, adding the byte '\ 0' at the end.
Not using const is dangerous, in fact the g ++ compiler generates a warning for the following code:
#include <stdio.h> int main(int argc, const char *argv[]) { char *p = "AString8"; printf("%s\n", p); printf("Last char: %c hex: %x\n", p[7], p[7]); printf("Last char + 1: %c hex: %x\n", p[8], p[8]); return 0; }
warning: deprecated conversion from string constant to 'char *
Program output:
Last char: 8 hex: 38 Last char + 1: hex: 0
source share