Explanation, someone??

Lars Wirzenius wirzeniu at klaava.Helsinki.FI
Sat Jun 15 23:28:52 AEST 1991


[ I have edited the code for brevity. --liw ]
>char *c[] = { "ENTER", "NEW", "POINT", "FIRST" };
>char **cp[] = { c+3, c+2, c+1, c};
>char ***cpp = cp;
>main() {
>  printf("%s", *++cpp);
                ^- are you certain there isn't a * missing here? The
type of *++cpp is char**, which is not what printf expects, but if you
insert the asterisk, you get **++cpp with the type char* and the output
is POINTERSTEW.

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

I didn't see anything wrong with the other program, "SWITCH SWAMP \n" is
the expected output (note the space before the newline). One way to
understand it is to go through it with a pen and some paper and keep
trace of each variable at every step.
-- 
Lars Wirzenius     wirzeniu at cc.helsinki.fi



More information about the Comp.lang.c mailing list