一个简短的编程难题

时间:2010-10-01 12:58:18

标签: c++ c

以下谜题的可能解释是什么:

#include <stdio.h>
int main(){
    static char *s[] = {"black","white","yellow","violet"};
    char *ptr[] = {s+3,s+2,s+1,s},***p;
    p = ptr;
    *++p;
    printf("%s",*--*++p + 3);
}

output

1 个答案:

答案 0 :(得分:7)

p = ptr;

这不是一个谜题。这是一段无效的代码,因为它为char**分配了char***。实际上问题发生在数组声明

s+3的类型为char**,但您将ptr声明为char*的数组。