Initial I didn't intend to go deeper of this example, coz I think it's just several lines, not big deal, but when I use the hello world to test and verify my thought, I find something quite abnormal! here is the code part without too much comments:
#include<stdio.h>
void concatenate(char s[], char c[]);
int main(){
char s[] = "hello";
char c[] = "world";
concatenate(s, c);
printf("%s\n",s);
return 0;
}
void concatenate(char s[], char c[]){
int i, j;
i = j = 0;
while(s[i] != '\0')/* find the end of s*/
i++;
while((s[i++] = c[j++]) != '\0') /* copy c string */
printf("%d,%c\n", i, s[i]);
printf("0,%c\n", s[0]);
printf("1,%c\n", s[1]);
printf("2,%c\n", s[2]);
printf("3,%c\n", s[3]);
printf("4,%c\n", s[4]);
printf("5,%c\n", s[5]);
printf("6,%c\n", s[6]);
printf("7,%c\n", s[7]);
printf("8,%c\n", s[8]);
printf("9,%c\n", s[9]);
printf("10,%c\n", s[10]);
}
how to run it? I'm using ubuntu 64-bit 18.04 version===> cc concat.c the output:
From the screenshot, it is so hard to imagine why the output is like this,
could anyone plz spend a bit of time explaining why it is this?? really appreciate it!