Check this obfuscated code in IOCCC. I'm trying to understand this.
int i;main(){for(;i["]<i;++i){--i;}"];read('-'-'-',i+++"hell\
o, world!\n",'/'/'/'));}read(j,i,p){write(j/p+p,i---j,i/i);}
Means:
int i;
main()
{
for(;i["]<i;++i){--i;}"];read('-'-'-',i+++"hello, world!\n",'/'/'/'));
}
read(j,i,p)
{
write(j/p+p,i---j,i/i);
}
Please explain me this : i["]<i;++i){--i;}"]
How this works as a condition statement here?
C indexing is kinda funky. a[b] is roughly equivalent to *(a+b) (with a degrading to a pointer to the first element). But addition is commutative, so a[b] and b[a] do the same thing. Thus:
i["]<i;++i){--i;}"]
is really just:
"]<i;++i){--i;}"[i]
but the reordering obfuscates by making it look like a normalish for loop if you miss the quotes. Since all values in the string are non-zero (and therefore "true") except for the NUL terminator, the loop would end when i was equal to the length of that string literal.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With