|  | 
 
| 
#include <STDIO.H>
x
马上注册,结交更多好友,享用更多功能^_^您需要 登录 才可以下载或查看,没有账号?立即注册  #include "string.h"
 
 int main()
 {
 int x = 1122867;  // 0x112233 == 1122867
 char str[10] ;
 // strlen()以'\0',作为结束标志,故strlen(str)不确定
 printf("strlen of str is: %d \n",strlen(str));
 
 //而sizeof(str)==10
 printf("sizeof of str is: %d \n",sizeof(str));
 
 printf("x is: %d\n",x); //x == 1122867
 
 //反汇编的时候发现,strcpy()只给"www.it315.o11"
 //分配了12个字节的空间,也许是用str做标准来分配的
 //所以,"www.it315.o11"最后的那个"1"会占用,变量x的
 //空间,此时0x112233变为,0x112231
 strcpy(str,"www.it315.o11");
 
 //但是,x != 0x112231,为什么呢,因为,strcpy()把'\0'
 //也复制了过来 x == 0x110031 == 1114161
 printf("x is: %d\n",x);
 
 //strlen()以'\0',作为结束标志(不包括'\0'),故strlen(str)==13
 printf("strlen of str is: %d \n",strlen(str));
 
 // sizeof()函数返回的是变量声明后所占的内存数,不是实际长度
 // 故sizeof(str)==10
 printf("sizeof of str is: %d \n",sizeof(str));
 
 return 0;
 }
 
 
 | 
 |