tags:

views:

216

answers:

1

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.

+6  A: 
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*.

Johannes Schaub - litb
Agreed, but it comes from this contest :http://effer56.iiita.ac.in/segmentation/home.html.
Debanjan
t's an invalid piece of code - And thus we vote NARQ
Henk Holterman
However,I might like to add that they have set some UB question in there contest.
Debanjan
@Debanjan - The guys who put of this question are no coding gurus, may have copied from somewhere else !!
DumbCoder