[cpp]
#include<stdio.h>
#include<string.h>
char arrays[] = {'a', 'b', 'c', '\0'};
char *s = "abc";
void test()
{
//arrays和s是相等的,如果arrays[] = {'a','b','c'}則不相等
if(strcmp(arrays, s) == 0)
printf("arrays == s\n");
printf("%d %d\n", sizeof(arrays), strlen(arrays));
char carray[] = {'a', 'b', 'c', 'd', 'e','f'};
printf("%d %d\n", sizeof(carray), strlen(carray));
}
int main()
{
test();
return 0;
}
/*
arrays == s
4 3
6 11
Press any key to continue
}
*/
#include<stdio.h>
#include<string.h>
char arrays[] = {'a', 'b', 'c', '\0'};
char *s = "abc";
void test()
{
//arrays和s是相等的,如果arrays[] = {'a','b','c'}則不相等
if(strcmp(arrays, s) == 0)
printf("arrays == s\n");
printf("%d %d\n", sizeof(arrays), strlen(arrays));
char carray[] = {'a', 'b', 'c', 'd', 'e','f'};
printf("%d %d\n", sizeof(carray), strlen(carray));
}
int main()
{
test();
return 0;
}
/*
arrays == s
4 3
6 11
Press any key to continue
}
*/為什麼strlen(carray)是11啊???Who can tell me why?