#include<stdio.h>
#include<string.h>
#define MSG "what \'s your name?"
#define LIM 5
#define MAX 10
int main()
{
char str1[]=MSG;
char *pstr=MSG;
printf("%p\n",MSG);
printf("pstr=%s\t&pstr=%p\t*pstr=%c\n",pstr,pstr,*pstr);
printf("str1=%s\t&str1=%p\t*str1=%c\n",str1,str1,*str1);
char str3[]="Hello world!";
printf("%lu\n",sizeof(str3));
char str2[13]={'H','e','l','l','o',' ','w','o','r','l','d','\0'};
printf("%lu\n",sizeof(str2));
char str4[12]={'H','e','l','l','o',' ','w','o','r','l','d'};
printf("%lu\n",sizeof(str4));
const char *pstr2="Hello world!";
printf("%lu\n",sizeof(pstr2));
printf("%p\n","Hello world!");
printf("pstr2=%s\t&pstr2=%p\t*pstr2=%c\n",pstr2,pstr2,*pstr2);
printf("str3=%s\t&str3=%p\t*str3=%c\n",str3,str3,*str3);
const char *parr1[LIM]={
{"红色"},
{"黄色"},
{"蓝色"},
{"绿色"},
{"黄色"}
};
char arr1[LIM][MAX]={
{"红色"},
{"黄色"},
{"蓝色"},
{"绿色"},
{"黄色"}
};
printf("sizeof(parr1)=%lu\n",sizeof parr1);
for(int i=0;i<LIM;i++)
{
printf("%s\n",parr1[i]);
}
printf("sizeof(arr1)=%lu\n",sizeof arr1);
for(int i=0;i<LIM;i++)
{
printf("%s\n",arr1[i]);
}
char *st1;
char ast[20];
gets(ast);
puts(ast);
fgets(ast,20,stdin);
puts(ast);
puts("*****************");
fputs(ast,stdout);
puts("*******************");
gets_s(ast,n);
return 0;
}
运行结果
![字符串的输入输出 字符串的输入输出](/default/index/img?u=aHR0cHM6Ly9waWFuc2hlbi5jb20vaW1hZ2VzLzY0NS84MGY3YjY5NWE3YjY2NGNjN2U1ZjMyYmIwYmU5MjJjZC5wbmc=)