#include
using namespace std;
#define ll long long
const int maxn = 110;
void test1() {
char buf[12];
// [Error] invalid conversion from 'const char*' to 'char' [-fpermissive]
// buf[4] = "hell";
}
void test2() {
char buf[4];
strcpy(buf, "hell");
printf("%s\n", buf);// hell
}
void test3() {
char buf[4];
printf("strlen(\"len\"): %d\n", strlen("len"));
memcpy(buf, "hello", strlen("len"));
printf("%s\n", buf);// hell
}
void test4() {
char *p;
// [Warning] deprecated conversion from string constant to 'char*' [-Wwrite-strings]
// p = "abc";
}
void test5() {
char s[] = "a3n9X*";
char *p = s;
printf("%c\n", *p + 4);// e
}
int main() {
// test2();
// test3();
test5();
}
c指针与字符串
关注
打赏