I am not able to understand this. Please explain.
Edit: It prints: 'hello, world!'
#include <stdio.h>
int i;
main()
{
for(;i["]<i;++i){--i;}"];read('-'-'-',i+++"hell\o, world!\n",'/'/'/'));
//For loop executes once, calling function read with three arguments.
}
read(j,i,p)
{
write(j/p+p,i---j,i/i); //how does it work? like printf?
}
Breaking is down you have:
The '{initial expr}' is blank so it does nothing. The '{conditional expr}' is
'i["]<i;++i){--i;}"]'
which is the same as
or
so it's looping until the expression is false (i.e. is hits the null at the end of the string).
The
{increment expr}
isIf you break that down the read parameters you have:
For parameter two you have:
which is the same as: i++ + "hell\o, world!\n"
So it increments the 'i' variable, this means the for loop will loop for the number of characters in conditional string "]
For the first time around you end up with:
The second time around the loop will be 1 + "hell\o, world!\n", etc.
So the second parameter is a pointer into the "hell\o, world!\n".
The third parameter is:
So the third parameter is always 1.
Now we break down the read function that calls write:
There are three parameters, the first is:
If read the link to the write function 1 is hardcoded to write to standard out.
The second parameter to write is
which is the same is
i-- - j
, where i is the pointer to the string andj = 0
, since i is post-decremented is doesn't do anything and'- 0'
does nothing, it's simply passing the pointer through to the write function.The third parameter is
'i / i
' which will always be1
.So for each call to 'read' it writes one character out of the "hell\o, world!\n" string each time.