sizeof包含'\0'
strlen 不包含'\0'
char s[] = "this is a test!";
sizeof(s) = s字符串+1;
#include
#include
int main(void){
char s[] = "this is a test!";
printf("sizeof(s) = %d\n",sizeof(s));
printf("strlen(s) = %d\n",strlen(s));
return 0;
}
/*
****************sizeof**************************
*purpose: Just for test
*/
int b[100];
void fun(int b[100]){
// b是指针而已,输出为多少呢?当然是4
// output: 4
printf("sizeof(b) = %d\n",sizeof(b) );
}
int main(void)
{
int *p = NULL;
int a[100];
// output : 4,4
printf("sizeof(p) = %d,sizeof(*p) = %d \n",\
sizeof(p),sizeof(*p) );
// output: 4*100,4
printf("sizeof(a) = %d,sizeof(a[100]) = %d \n",\
sizeof(a),sizeof(a[100]) );
// output:4,4
printf("sizeof(&a) = %d,sizeof(&a[0]) = %d \n",\
sizeof(&a),sizeof(&a[0]) );
fun(b);
return 0;
}
阅读(1263) | 评论(0) | 转发(0) |