在修改字符串时,我们需要将字符串指针的地址传入至函数中,如下:
void print(char *str, char **strAddr) {
str++;
cout << str << endl;
*strAddr = str;
}
即改变指针指向的位置,调用过程如下所示:
char *a = "abcdefg";
print(a, &a);
cout << a << endl;
结果如下:
在修改字符串时,我们需要将字符串指针的地址传入至函数中,如下:
void print(char *str, char **strAddr) {
str++;
cout << str << endl;
*strAddr = str;
}
即改变指针指向的位置,调用过程如下所示:
char *a = "abcdefg";
print(a, &a);
cout << a << endl;
结果如下: