Code:
1#include <iostream>2#include <cstdio>3 4 using namespacestd;5 6 voidFunChar**p) {7 //char* s = "World";8 CharS[] =" World";9printf"Point s =%p\n", s);Ten*p =s; Oneprintf"Point p =%p\n",*p); A } - - intMain () { the - Char*p ="Hello"; -printf"Point p =%p\n", p); -cout<<"func Start"<<Endl; +Fun (&p); -cout<<"Func End"<<Endl; +printf"Point p =%p\n", p); Acout<<p<<Endl; at - return 0; -}
Output:
Point P = 0x400accfunc startpoint s = 0x7ffe10660100point p = 0x7ffe10660100func Endpoint p = 0x7ffe10660100 '
If the 8th line of code is commented and replaced by the 7th line of the comment, the output is
Point P = 0x400ac2func startpoint s = 0x400aa0point p = 0x400aa0func Endpoint p = 0x400aa0world
Analysis:
The constant string is stored in the literal constant area, and the character array is stored on the stack.
String storage locations in C/