开发者

A short programming puzzle [closed]

开发者 https://www.devze.com 2023-01-18 21:01 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 12 years ago.

What could the possible explanation for the following puzzle :

开发者_如何学运维#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.


p = ptr;

This is not a puzzle. It's an invalid piece of code since it assigned a char** to a char***. Actually the problem happens in the array declaration

s+3 has type char**, but you declare ptr as an array of char*.

0

精彩评论

暂无评论...
验证码 换一张
取 消