11 c
我无法理解这一点.请解释.
编辑:它打印:'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?
}
Run Code Online (Sandbox Code Playgroud)
Sha*_*ell 25
打破了你有:
for({initial expr};{conditional expr};{increment expr})
Run Code Online (Sandbox Code Playgroud)
'{initial expr}'是空白的,所以它什么都不做.'{conditional expr}'是'i["]<i;++i){--i;}"]'
这是一样的
"]<i;++i){--i;}"[i]
Run Code Online (Sandbox Code Playgroud)
要么
const char* str = "]<i;++i){--i;}";
for (; str[i]; )
Run Code Online (Sandbox Code Playgroud)
所以它循环直到表达式为假(即在字符串的末尾命中空值).
该{increment expr}IS
read('-'-'-',i+++"hell\o, world!\n",'/'/'/')
Run Code Online (Sandbox Code Playgroud)
如果你打破了读取参数,你有:
'-' - '-' == char('-') - char('-') == 0
Run Code Online (Sandbox Code Playgroud)
对于参数2,您有:
i+++"hell\o, world!\n"
Run Code Online (Sandbox Code Playgroud)
这与:i ++ +"hell\o,world!\n"相同
所以它递增'i'变量,这意味着for循环将循环条件字符串"]中的字符数
第一次你最终得到:
Run Code Online (Sandbox Code Playgroud)0 + "hell\o, world!\n"
循环第二次将是1 +"地狱\ o,世界!\n"等.
所以第二个参数是指向"地狱\ o,世界!\n"的指针.
第三个参数是:
'/'/'/' == '/' / '/' == char('/') / char('/') == 1
Run Code Online (Sandbox Code Playgroud)
所以第三个参数总是1.
现在我们分解调用write的read函数:
write(j/p+p,i---j,i/i);
Run Code Online (Sandbox Code Playgroud)
有三个参数,第一个是:
Run Code Online (Sandbox Code Playgroud)j/p+p where j == 0, p == 1 so 0/1+1 == 1.
如果读取,写入功能1的链接被硬编码以写入标准输出.
要写的第二个参数是
i---j
Run Code Online (Sandbox Code Playgroud)
这是相同的i-- - j,其中我是指向字符串的指针j = 0,因为我是后递减的是什么都不做什么都不做'- 0',它只是将指针传递给写入函数.
第三个参数是'i / i'将永远是1.
因此,对于每次调用'read',它每次都会从"地狱\ o,世界!\n"字符串中写出一个字符.