自己思考:
#include <stdio.h>
#include <string.h>
int main()
{
char array[6] = "Hello";
char *p = array;
printf("The result of sizeof is %d\n\n", sizeof(array) );
printf("The result of stringlen is %d\n", strlen(array) );
printf("The result of sizeof is %d\n", sizeof("\0") );
printf("%s\n", array);
printf("%c\n", *p);
printf("%d\n", sizeof(int));
printf("%d\n", sizeof(char));
printf("%d\n", sizeof(*p));
printf("%d\n", sizeof(p));
return 0;
}
The result of sizeof is 6
The result of stringlen is 5
The result of sizeof is 2
Hello
H
4
1
1
4
Press any key to continue
#include <stdio.h>
#include <string.h>
int main()
{
char array[3] = "Hello";
char *p = array;
printf("The result of sizeof is %d\n\n", sizeof(array) );
printf("The result of stringlen is %d\n", strlen(array) );
printf("The result of sizeof is %d\n", sizeof("\0") );
printf("%s\n", array);
printf("%c\n", *p);
printf("%d\n", sizeof(int));
printf("%d\n", sizeof(char));
printf("%d\n", sizeof(*p));
printf("%d\n", sizeof(p));
return 0;
}
The result of sizeof is 3
The result of stringlen is 7
The result of sizeof is 2
Hel+乱码
H
4
1
1
4
Press any key to continue
sizeof and strlen
最新推荐文章于 2018-09-06 23:44:00 发布