#include<iostream>
#include <string.h>
using namespace std;
int main()
{
const char* x1 = "abcdef", * x2 = "ab";
x1++; x2++;
cout << x1 << endl<<x2<<endl;
cout << strcmp(x1, x2);
return 0;
}
应该是不一定是1,有机会
你的问题其实就是问,能不能修改x1 x2两个指针的指向,或者修改"abcdef"或者"ab"这两个常量。
前者可以,后者不可以
const char* x1 = "abcdef", * x2 = "ab";
x1++; x2++;
cout << x1 << endl<<x2<<endl;
x1 = "a";
x2 = "a";
cout << strcmp(x1, x2);