总结: 1:计算char *a的长度需要strlen 计算char[]的长度需要sizeof 2:int * char* ->指针可以互转 3:strlen 计算的是真实有效的长度
char *a = "hello"; char b[20] = "hello"; char c[] = "\x00\x00\x00\x01\x00\x00\x00\x01"; char d[] = "hello"; char *e = "\x01"; printf("==%s",a); printf("==%s",b); printf("ccc==%s",c); printf("eee==%s",e); printf("==%s",d); printf("\n"); printf("==%lu",(sizeof a)); //指针所以是8 printf("==%lu",(sizeof b)); //写死了所以是20 printf("==%lu",(sizeof c)); //自由 一个\x00占一个byte printf("==%lu",(sizeof d)); //自由 printf("==%lu",strlen(a)); //想计算*a的长度 printf("==%lu",strlen(e)); //想计算*e的长度 uint8_t *p_payload = (uint8_t *)a; printf("\n"); printf("==%lu",strlen((char *)p_payload)); printf("==%s",p_payload); printf("\n"); char dd[20]; memcpy(dd,b,(sizeof b)); printf("==%lu",(sizeof dd)); printf("dd==%s",dd);