标签:
1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <string.h> 4 int main() 5 { 6 char *p="wangddd"; 7 printf("%d\n",sizeof(p));//输出4,指针类型 8 9 char x[8]; 10 printf("%d\n",sizeof(x));//输出8,所占内存数 11 12 printf("%s\n",strncpy(x,"wangddddd",sizeof(x)));//返回x指针,正常显示前7位 13 //strncpy返回值是一个指针x 14 printf("%d\n",sizeof(strncpy(x,"wangddddd",sizeof(x))));//输出4 15 printf("%d\n",strlen(strncpy(x,"jskjksjdf",sizeof(x))));//随机 取决于编译环境 16 printf("%d\n",strlen(strncpy(x,"jskjkse",sizeof(x))));//输出7 17 18 char y[5]="w c"; 19 printf("%d\n",strlen(y));//输出3 20 printf("%d\n",sizeof(y));//输出5 21 22 return 0; 23 }
标签:
原文地址:http://www.cnblogs.com/dongzhuangdian/p/5059886.html