還是舉一個例子,將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;
}
}