已知char **s;下面正确语句是()A,s="ABCDEF";B,*s="ABCDEF";C,**s="ABCDEF

1个回答

  • B才是对的吧不考虑类型强转并且 在此前有 s=new char*;

    typedef char * pchar;

    pchar *s;

    s可以看成以上定义 也许更方便理解

    typeid("ABCDEF").name()是const char [7];

    typeid(*s).name()是char *;

    typeid(**s).name()是char;

    如果考虑强转可以参考如下

    s=new char **;//s=(char **)(void*)("ABCDEF");

    *s=new char *;//**s=(char)(long)(void*)("ABCDEF");

    //*s=(char*)(long)('A');

    如下操作经过VS2010 测试

    char **s,**ppt,*pt,p;

    cout

    *s=pt=new char ;

    **s=p='A';

    **s=(char)(long)(void*)"A";

    *s=(char*)(long)'a';

    *s="B";

    s=(char **)(void *)"C";

    s=(char**)(void*)(long)'d';

    delete ppt;

    delete pt;