变态的指针用法

#include <windows.h>
#include <iostream>
using std::cout;         
using std::endl;


int main()
{
 char *str[]={"Welcome","to","Fortemedia","Nanjing"};
 char **p=str+1;      //p指向str[1]       
 str[0]=(*p++)+2;    //p指向str[2]        str[0]="\0"
 str[1]=*(p+1);        //str[1]="Nanjing"    
 str[2]=p[1]+3;        //str[2]="jing"    注意:p现在指向str[2],即p[0]="jing"
 str[3]=p[0]+(str[2]-str[1]);    //str[2]-str[1]=p[1]+3-*(p+1) =3   ,看上两步      
 printf("%s\n",str[0]);
 printf("%s\n",str[1]);
 printf("%s\n",str[2]);
 printf("%s\n",str[3]);

 system("pause");
    return 0;
}

打印结果:

我刚看到这个的时候,不晓得有些结果怎么来的,后来认真的到机子上调试了一下,终于明白了!  

posted on 2011-08-22 08:49  原来...  阅读(549)  评论(0)    收藏  举报

导航