可以分析下结果为什么是1711717吗


#include <stdio.h>
#include<string.h>
void fun(char *w,int n)
{
    char t,*s1,*s2;
    s1=w;s2=w+n-1;
    while(s1<s2)
    {
        t=*s1++;*s1=*s2--;*s2=t;
    }
}
int main()
{
    char p[]="1234567";
    fun(p,strlen(p));
    puts(p);
    return 0;
}






我来教你·

oid fun(char *w,int n)
{
    char t,*s1,*s2;
    s1=w;s2=w+n-1;//s1是第一个字符的位置,s2是最后一个字符的位置s1=&p[0],s2=&[6]
    while(s1<s2)
    {                   //第一次满足s1<s2,执行交换   //第二次s1(1)<s2(5),执行交换 //第三次是s1(2)<s2(4),执行交换 最后s1(3)s2(3)结束·
        t=*s1++;        //t=p[0]='1',s1=&p[1]    //t=p[1]=7 s1=&p[2]       //t=p[2]=1,s1=&p[3]
        *s1=*s2--;      //p[1]=p[6]='7',s2=&p[5] //p[2]=p[5]=1,s2=&p[4]    //p[3]=p[4]=7,s2=&p[3]
        *s2=t;          //p[5]='1'               //p[4]=7                  //p[3]=1
    }  //=> p[]='1711717'
}