#include <stdio.h>intMain () {//string constants, which are stored in the memory constant area. //There is a cache mechanism for a constant-only memory.//when different pointers point to the same constant value,//in fact, these pointers point to the same block of constant memory//and the constant area memory is not allowed to be modified by the program char *str1 = "Hello"; char *str2 = "Hello"; //Error//* (str1+2) = ' A '; printf ("str1 =%p\n", STR1); printf ("str2 =%p\n", STR2); //The string variable is stored in the stack memory,//different character arrays point to the same string value,//It's also stored in two different pieces of memory.//and stack memory is allowed to be modified by the programchar str3[] = "Hello"; Char str4[] = "Hello"; No error//str3[2]= ' A ';printf ("STR3 =%p\n", STR3); printf ("STR4 =%p\n", STR4); return 0;}
Results:
The difference between a C-language pointer string and a character array string