#include<string.h> // 导入头文件<string.h>
#include<stdio.h> // 导入头文件<stdio.h>
char *fun(char *t) // 定义函数, 名称fun, 输入参数为char *, 返回值为char *
{
char *p = t; // 把t的值赋值给p, 相当于p指向与t相同的字符串
return p + strlen(t) / 2; // strlen返回值为字符串长度, 然后p位移其一半(向下取整)的距离并返回值
}
int main(int argc, char *argv[])
{
char *str = "abcdefgh"; // str指向字符串“abcdefgh”
str = fun(str); // str调用fun函数, 参数为str, 并将返回值赋值给str
puts(str); // 此时str指向e, 输出为“efgh\n”
return 0;
}
追问谢谢!