#include "string.h" #include "stdio.h"
void main() { int i; char testString[20];
for(i = 0; i < 10; i++) { testString[i] = '0'; } printf("\n%d", strlen(testString)); printf("\n%d", sizeof(testString)); //
printf("\n%s", testString); //
{ int i; char testString[20] = "abc";
for(i = 0; i < 10; i++) { testString[i] = '0'; } printf("\n%d", strlen(testString)); printf("\n%d", sizeof(testString)); }
printf("\n************************"); testString[0] = 'a'; testString[1] = 'a'; testString[2] = 'a'; printf("\n%d", strlen(testString)); //
printf("\n%d", sizeof(testString)); //
printf("\n%s", testString); //
for(i = 0; i< 10; i++) { testString[i] = '\0'; } printf("************************"); printf("\n%d", strlen(testString)); //
printf("\n%d", sizeof(testString)); //
printf("\n%s", testString); //
{ char testString[] = "abc"; printf("\n***************************"); printf("\n%d", strlen(testString)); //
printf("\n%d", sizeof(testString)); //
printf("\n%s", testString); //
}
{ char testString[3] = "abc"; printf("\n************************"); printf("\n%d", strlen(testString)); //
printf("\n%d", sizeof(testString)); //
printf("\n%s", testString); //
}
{ char testString[20] = "abc"; printf("\n************************"); printf("\n%d", strlen(testString)); //
printf("\n%d", sizeof(testString)); //
printf("\n%s", testString); //
}
printf("\n************************"); /*testString[0] = 'a'; testString[1] = 'b'; testString[2] = 'c';*/ for(i = 0; i < 19; i++) { testString[i] = '0'; } printf("\n%d", strlen(testString)); //
printf("\n%d", sizeof(testString)); //
printf("\n%s\n", testString); //
}
==================================
下面是我机子上的运行结果
21 20 0000000000烫烫烫烫烫
10 20 ************************ 21 20 aaa0000000烫烫烫烫烫 ************************ 0 20
*************************** 3 4 abc ************************ 7 3 abc蘟bc ************************ 3 20 abc ************************ 21 20 0000000000000000000? Press any key to continue
|