奇妙的现象,但总有规律

    技术2022-05-13  24

    1 #include <stdio.h>  2 #include <string.h>  3   4 int main(){  5          char *t1="machaomachao";  6          char t2[17]="machao";  7          char t3[128];  8          char t4[128];  9          printf("input for t3/n"); 10         fgets(t3,sizeof(t3),stdin);   //输入machao,回车。 最多只能输入(接收)127个有效字符 11         printf("input for t4/n"); 12         scanf("%s",t4);                   //输入machao,回车。  13         printf("result: /n"); 14         printf("t1:%d/n",sizeof(t1));//4                          求的所指针所占大小,4个字节 15         printf("t2:%d/n",sizeof(t2));//17                        求的所数组容量大小 16         printf("t1:%d/n",strlen(t1));//12                        求的是指向内容真是大小 17         printf("t2:%d/n",strlen(t2));//6                          求的是所含内容真是大小 18         printf("t3:%d/n",strlen(t3));//7                          结果包含/0 19         printf("t3:%d/n",sizeof(t3));//128                      求的是c的容量 20         printf("t3:%s",t3);               //machao                正常输出,自动在最后加上/n 21         printf("t3:%s",&t3);            //machao                 加与不加&没什么影响,自动在最后加上/n 22         printf("t4:%d/n",strlen(t4));//6                           同上  23         printf("t4:%s/n",t4);           //machao                 正常输出 24         printf("t4:%s/n",&t4);        //machao                  正常输出   25         return 0; 26 }


    最新回复(0)