[chbot] !!!!!!!! Choc fish challenge 2 !!!!!!!!! --> original

Charles Manning manningc2 at actrix.gen.nz
Mon Aug 1 22:12:12 BST 2011


On Monday 01 August 2011 14:13:41 Charles Manning wrote:
> First the rules....
>
> The last choc fish challenge was not very fair because it was finished by
> the time normal working people accessed their emails.
>
> This time the first correct answer after  8pm on Tuesday will win.
>
> This challenge tests your C programming knowledge. It is considered
> cheating to:
> * Use Google or equivalents (or even Bing)!
> * Use a compiler to verify your answers.
> * Look stuff up in specs, books, etc.
>
>
> Here goes:
>
> Under what conditions does the following compile and what will happen when
> it executes?
>
>   while(x[j] == j[x]){
> 	j++; x++;
>   }


This has been replaced by Andre's choc fish challenge 2.

As Andre said, this will work where one of x or j is a mutable pointer (ie not 
a const pointer) and the other is an ordinal (ie integer equivalent). 
Exceptions aside, this will loop forever as x[j[] and j[x] are equivalent.

Under the hood, x[y] just becomes equivalent to *(x + y). Indeed *(x) can be 
replaced by 0[x].

That means pretty bizarre constructs like

3["abcdef" -1] 

are legal (equivalent to "abcdef"[2] which is 'c').

-- Charles



More information about the Chchrobotics mailing list