1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| #include <cstring> #include <cstdio> #include <iostream>
int main() { const char* c1 = "hello!1+"; char* c2 = "hello!2+"; const char c3[] = "hello!3"; char c4[] = "hello!4";
printf("%s, sizeof = %lld, len = %lld\n", c1, sizeof(c1), strlen(c1)); printf("%s, sizeof = %lld, len = %lld\n", c2, sizeof(c2), strlen(c2)); printf("%s, sizeof = %lld, len = %lld\n", c3, sizeof(c3), strlen(c3)); printf("%s, sizeof = %lld, len = %lld\n", c4, sizeof(c4), strlen(c4));
*c4 = 'A';
printf("%s, sizeof = %lld, len = %lld\n", c1, sizeof(c1), strlen(c1)); printf("%s, sizeof = %lld, len = %lld\n", c2, sizeof(c2), strlen(c2)); printf("%s, sizeof = %lld, len = %lld\n", c3, sizeof(c3), strlen(c3)); printf("%s, sizeof = %lld, len = %lld\n", c4, sizeof(c4), strlen(c4));
system("pause"); }
|