#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void main()
{
char *str = "123456";
char str2[10]="123456";
printf("sizeof char is %d\n",sizeof(char));
printf("sizeof char* is %d\n",sizeof(char*));
printf("sizeof int is %d\n",sizeof(int));
printf("sizeof int* is %d\n",sizeof(int*));
printf("str is %s\n",str);
printf("sizeof str is %d\n",sizeof(str));
printf("lenof str is %d\n",strlen(str));
printf("str[10] is %s\n",str2);
printf("sizeof str2[10] is %d\n",sizeof(str2));
printf("lenof str2[10] is %d\n",strlen(str2));
}
#include <stdlib.h>
#include <string.h>
void main()
{
char *str = "123456";
char str2[10]="123456";
printf("sizeof char is %d\n",sizeof(char));
printf("sizeof char* is %d\n",sizeof(char*));
printf("sizeof int is %d\n",sizeof(int));
printf("sizeof int* is %d\n",sizeof(int*));
printf("str is %s\n",str);
printf("sizeof str is %d\n",sizeof(str));
printf("lenof str is %d\n",strlen(str));
printf("str[10] is %s\n",str2);
printf("sizeof str2[10] is %d\n",sizeof(str2));
printf("lenof str2[10] is %d\n",strlen(str2));
}
sizeof char is 1
sizeof char* is 4
sizeof int is 4
sizeof int* is 4
str is 123456
sizeof str is 4
lenof str is 6
str[10] is 123456
sizeof str2[10] is 10
lenof str2[10] is 6
sizeof对于指针求指针类型的大小(32位机为4字节),对于数组求数组所占大小