还是举一个例子,将str = strTmp
掉,对比前后输出的变化。
#include <iostream>
#include <string>
#include <vector>
using namespace std;
void foo(char **str) {
char *strTmp[4] = {nullptr};
strTmp[0] = reinterpret_cast<char *>('a');
str = strTmp;
str[0] = reinterpret_cast<char *>('a');
}
int main() {
char *str[4] = {nullptr};
foo(str);
if (str[0] == nullptr) {
cout << "11" << endl;
} else {
cout << "22" << endl;
}
}