69,370
社区成员
发帖
与我相关
我的任务
分享
1 #include <stdio.h>
2
3 void show_chars(char *a, int len)
4 {
5 int i;
6
7 for (i=0; i<len; i++)
8 printf("%d\t",a[i]);
9 printf("\n");
10 }//show_chars
11
12 int main()
13 {
14 char *s1 = "abc";
15 char s2[3] = "abc";
16 char s3[4] = "abc";
17
18 show_chars( s1, sizeof(s1));
19 show_chars( s2, sizeof(s2));
20 show_chars( s3, sizeof(s3));
21
22 return 0;
23 }
97 98 99 0
97 98 99
97 98 99 0
#include <stdio.h>
int main(void)
{
char *p1="abc";
char p2[3]="abc";
printf("%x%x%x%x",*p1,*(p1+1),*(p1+2),*(p1+3));
printf("\n");
printf("%x%x%x%x",p2[0],p2[1],p2[2],p2[3]);
return 0;
}
#include <stdio.h>
int main(void)
{
char *p1="abc";
char p2[3]="abc";
char *p3=p2+3;
printf("%x%x%x%x",*p1,*(p1+1),*(p1+2),*(p1+3));
printf("\n");
printf("%s",p2);
*p3='\0';
printf("\n");
printf("%s",p2);
return 0;
}