一、 阅读程序,写出结果
// 1、
#include <iostream>
using namespace std;
void fun1(char* s1, char* s2)
{
int i = 0;
for (; *s1 == *s2; s1++, s2++)
{
i++;
}
cout << s1 << endl;
cout << i << endl;
}
void fun2(char*& s1, char*& s2)
{
int i = 0;
for (; *s1 == *s2; s1++, s2++)
{
i++;
}
*(s1 - 1) = '\0';
*(s2 - 1) = '\0';
}
int main()
{
char string1[] = "I love Nanjing";
char string2[] = "I love Southeast University";
char* p1 = string1;
char* p2 = string2;
fun1(p1, p2);
fun2(p1, p2);
cout << p1 << endl;
cout << p2 << endl;
cout << string1 << endl;
cout << string2 << endl;
return 0;
}
考察知识点指针引用,字符串存储。
重难点解析:
1、可以使用字符数组或者字符指针去指向一个字符串,字符串在内存中实际按照字符数组的形式进行存储,形如"123"的字符串在内存中是长度为4的字
607



被折叠的 条评论
为什么被折叠?



