#include <stdio.h>
#include <string.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
char a[]="aaaaa";
printf("%d",sizeof(a));
return 0;
#include <string.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
char a[]="aaaaa";
printf("%d",sizeof(a));
return 0;
}
输出为,6,a数组的大小,包含最后的'\0'符,所以是6个字节
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
char *a="aaaaa";
printf("%d",sizeof(a));
return 0;
}
输出为8,因为我的电脑是64位的,所以char *a,a表示的是一个指针,也就是地址,地址是64位的,所以大小是8个字节
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
char a[]="aaaaa";
printf("%d",strlen(a));
return 0;
}
输出的结果是5,不包含最后的'\0'