指针的一道题

#include <stdio.h>

char *c[] = {"HELLO","NEW","WORLD","SAYHI"};
char **cp[]={c+3,c+2,c+1,c};
char ***cpp=cp;

int main(void)
{
    printf("%s\n",*cpp[2]);
    printf("%s\n",**++cpp);
    printf("%s\n",*--*++cpp+3);
    printf("%s\n",**cpp);
    printf("%s\n",*cpp[-2]+3);

    printf("%s\n",cpp[-1][-1]+1);
    printf("%s\n",cpp[-1]);
}

#include <iostream>
#include <string>
using namespace std;

int main()
{
    char *c[] = {"HELLO","NEW","WORLD","SAYHI"};
    char **cp[]={c+3,c+2,c+1,c};
    char ***cpp=cp;
    cout<< sizeof(char*) <<endl;
    cout<< sizeof(char**) <<endl;
    cout<< sizeof(char***) <<endl;
    cout<< "c:\t\t\t"             << c <<endl;
    cout<< "c[0]:\t\t\t"          << c[0] <<endl;
    cout<< "c[1]:\t\t\t"          << c[1] <<endl;
    cout<< "&c[0]:\t\t\t"         << &c[0] <<endl;
    cout<< "&c[1]:\t\t\t"         << &c[1] <<endl;
    cout<< "&c[2]:\t\t\t"         << &c[2] <<endl;
    cout<< "&c[3]:\t\t\t"         << &c[3] <<endl;

    cout<< "*c:\t\t\t"            << *c <<endl;
    cout<< "*(c+1):\t\t\t"        << *(c+1)<<endl;
    cout<< "&c:\t\t\t"            << &c<<endl;

    cout<< "c[0]:\t\t\t"          << c[0]<<endl;
    cout<< "&c[0]:\t\t\t"         << &c[0]<<endl;
    cout<< "*c[0]:\t\t\t"         << *c[0]<<endl;
    cout<< "*(c[0]+1):\t\t"       << *(c[0]+1)<<endl;
    cout<< "*(&c+1):\t\t"         << *(&c+1) <<endl;
    cout<< "*(&c[0]+1):\t\t"      << *(&c[0]+1)<<endl;
    cout<< "cp\t\t\t"             << cp <<endl;
    cout<< "*cp\t\t\t"            << *cp<<endl;
    cout<< "*(cp+1)\t\t\t"        << *(cp+1)<<endl;
    cout<< "cp[0]\t\t\t"          << cp[0]<<endl;
    cout<< "&cp[0]\t\t\t"         << &cp[0]<<endl;
    cout<< "**cp\t\t\t"           << **cp<<endl;
    cout<< "&cp\t\t\t"            << &cp<<endl;
    cout<< "&cp[0]\t\t\t"         << &cp[0]<<endl;
    cout<< "*(*cp+1)\t\t"         << **(cp+1)<<endl;
    cout<< "cpp\t\t\t"            << cpp<<endl;
    cout<< "&cpp\t\t\t"           << &cpp<<endl;
    cout<< "*cpp\t\t\t"           << *cpp<<endl;
    cout<< "*(cpp+1)\t\t"         << *(cpp+1)<<endl;
    cout<< "*(&cpp)\t\t\t"        << *(&cpp)<<endl;
    cout<< "*(&cpp+1)\t\t"        << *(&cpp+1)<<endl;
    cout<< "**cpp\t\t\t"          << **cpp<<endl;
    cout<< "***cpp\t\t\t"         << ***cpp<<endl;




//    cout<< <<endl;
//    cout<< <<endl;
//    cout<< <<endl;
//    cout<< <<endl;
//    cout<< <<endl;
//    cout<< <<endl;
}
8
8
8
c:                   0x61fe00
c[0]:                   HELLO
c[1]:                   NEW
&c[0]:                  0x61fe00
&c[1]:                  0x61fe08
&c[2]:                  0x61fe10
&c[3]:                  0x61fe18
*c:                     HELLO
*(c+1):                 NEW
&c:                     0x61fe00
c[0]:                   HELLO
&c[0]:                  0x61fe00
*c[0]:                  H
*(c[0]+1):              E
*(&c+1):                0x61fe20
*(&c[0]+1):             NEW
cp                      0x61fde0
*cp                     0x61fe18
*(cp+1)                 0x61fe10
cp[0]                   0x61fe18
&cp[0]                  0x61fde0
**cp                    SAYHI
&cp                     0x61fde0
&cp[0]                  0x61fde0
*(*cp+1)                WORLD
cpp                     0x61fde0
&cpp                    0x61fdd8
*cpp                    0x61fe18
*(cpp+1)                0x61fe10
*(&cpp)                 0x61fde0
*(&cpp+1)               0x61fe18
**cpp                   SAYHI
***cpp                  S
上一篇:IM在线聊天-微聊即时通讯完整源码


下一篇:文件管理基础命令之二