C 这个❤;代码工作?
我偶然发现了这个密码 现在它不是那么感人,但还是有点神秘 那么,有人能解释一下这段代码是如何打印出《我喜欢你》的吗 更新: 为变量C 这个❤;代码工作?,c,C,我偶然发现了这个密码 现在它不是那么感人,但还是有点神秘 那么,有人能解释一下这段代码是如何打印出《我喜欢你》的吗 更新: 为变量$、\u和\u以及扩展的三元运算符提供了更好的名称: int a[] = { 0x69, 0154, 107, 'e', 0x79, 0157, 117, 'v', 0x6a }, x, y; x = y ^ y; y = x; while (x < (-(~(1 << 3)) + 3)) { if (x == 1 <<
$
、\u
和\u
以及扩展的三元运算符提供了更好的名称:
int a[] = { 0x69, 0154, 107, 'e', 0x79, 0157, 117, 'v', 0x6a }, x, y;
x = y ^ y;
y = x;
while (x < (-(~(1 << 3)) + 3))
{
if (x == 1 << 1 || x == -(~(1 << 3)) || x == 11)
putchar (*(a + (1 >> 1)));
else
{
putchar (*(y++ + a));
if (x == 1 >> 1 || x == 1 << 2 || x == (1 << 3) - 1)
putchar (' ');
else
1;
}
x++;
}
inta[]={0x690154107'e',0x790157117'v',0x6a},x,y;
x=y^y;
y=x;
当(x<(~(1>1 | | x==1重写代码时,给出:
int arr1[] = { 'i', 'l', 'k', 'e', 'y', 'o', 'u', 'v', 'j'};
int i0, i1; // Moved to new line instead of using ,
i0 = 0; // i0 = i1 ^ i1;
i1 = i0;
while (i0 < 12) // All strange constant like (1<<3) recalculated
{
if (i0 == 2 || i0 == 9 || i0 == 11) // "? :" replaced by if
{
putchar(*arr1);
}
else
{
putchar (*(arr1 + i1));
++i1;
if (i0 == 0 || i0 == 4 || i0 == 7)
{
putchar(' ');
}
}
i0++;
}
intarr1[]={'i','l','k','e','y','o','u','v','j'};
int i0,i1;//移动到新行,而不是使用,
i0=0;//i0=i1^i1;
i1=i0;
while(i0<12)//(1)尝试以下更改:使用更好的变量名;简化常量表达式(例如,尽管尚未初始化,\uuuuu
,但我仍会看到\uuu=\uuu^
。这可能属于未定义行为的范畴。@RSahu从技术上讲,可能是这样。尽管您知道它是如何工作的,但任何XOR本身都会保证结果为0。@inetknght仅适用于初始化值;未初始化值可能不同于每次阅读时,我都不知道这些反对票是怎么回事。这是一个非常有主题性(而且非常棒)的问题。添加一个解释,唯一重复的字母是代码插入的'I'
(*arr1
),或者在适当的地方加上一个空格。好吧,你发布了答案!i0
计算字母(空格除外)在输出中。i1
为源数组中的字母编制索引。在适当的位置,代码要么使用第一个数组元素*arr1
输出源数组中未依次出现的'i'
,要么从源数组中输出下一个字母,然后在正确的位置输出spa总工程师。
int a[] = { 0x69, 0154, 107, 'e', 0x79, 0157, 117, 'v', 0x6a }, x, y;
x = y ^ y;
y = x;
while (x < (-(~(1 << 3)) + 3))
{
if (x == 1 << 1 || x == -(~(1 << 3)) || x == 11)
putchar (*(a + (1 >> 1)));
else
{
putchar (*(y++ + a));
if (x == 1 >> 1 || x == 1 << 2 || x == (1 << 3) - 1)
putchar (' ');
else
1;
}
x++;
}
int arr1[] = { 'i', 'l', 'k', 'e', 'y', 'o', 'u', 'v', 'j'};
int i0, i1; // Moved to new line instead of using ,
i0 = 0; // i0 = i1 ^ i1;
i1 = i0;
while (i0 < 12) // All strange constant like (1<<3) recalculated
{
if (i0 == 2 || i0 == 9 || i0 == 11) // "? :" replaced by if
{
putchar(*arr1);
}
else
{
putchar (*(arr1 + i1));
++i1;
if (i0 == 0 || i0 == 4 || i0 == 7)
{
putchar(' ');
}
}
i0++;
}
main()
{
int $[] = {0x69, 0154,107, 'e',0x79,0157, 117,'v',0x6a} , _, __;
_ = __^__;
__ = _;
while(_ < (-(~(1<<3))+3))
{
(_ == 1<<1 || _ == -(~(1<<3)) || _ == 11) ?
putchar(*($ + (1>>1))) :
putchar(*(__++ +$)), (_ == 1 >> 1 || _ == 1<<2 || _ == (1<<3)-1) ?
putchar(' ') : 1;
_++;
}
}
main()
{
int arr1[] = {0x69, 0154,107, 'e',0x79,0157, 117,'v',0x6a} , i0, i1;
i0 = i1^i1;
i1 = i0;
while(i0 < (-(~(1<<3))+3))
{
(i0==1<<1 || i0== -(~(1<<3)) || i0 == 11) ?
putchar(*(arr1+(1>>1))) :
putchar(*(i1++ +arr1)), (i0 == 1 >> 1 || i0 == 1<<2 || i0 == (1<<3)-1) ?
putchar(' ') : 1;
i0++;
}
}
main()
{
int arr1[] = {0x69, 0154,107, 'e',0x79,0157, 117,'v',0x6a} , i0, i1;
i0=i1^i1;
i1=i0;
while(i0 < (-(~(1<<3))+3))
{
if (i0 == 1<<1 ||i0== -(~(1<<3)) || i0 == 11)
{
putchar(*(arr1+(1>>1)));
}
else
{
putchar(*(i1++ +arr1));
if (i0 == 1 >> 1 || i0 == 1<<2 || i0 == (1<<3)-1)
{
putchar(' ');
}
else
{
1; // This does nothing so it can be removed
}
}
i0++;
}
}
main()
{
int arr1[] = { 'i', 'l', 'k', 'e', 'y', 'o', 'u', 'v', 'j'} , i0, i1;
i0 = 0;
i1 = i0;
while(i0 < 12)
{
if (i0 == 2 || i0 == 9 || i0 == 11)
{
putchar(*(arr1));
}
else
{
putchar(*(i1++ +arr1));
if (i0 == 0 || i0 == 4 || i0 == 7)
{
putchar(' ');
}
}
i0++;
}
}
main()
{
int arr1[] = { 'i', 'l', 'k', 'e', 'y', 'o', 'u', 'v', 'j'}; // Move i0 and
// i1 to nextt line
int i0, i1;
i0 = 0;
i1 = i0;
while(i0 < 12)
{
if (i0 == 2 || i0 == 9 || i0 == 11)
{
putchar(*arr1);
}
else
{
putchar(*(arr1 + i1)); // Splitted into two lines
++i1;
if (i0 == 0 || i0 == 4 || i0 == 7)
{
putchar(' ');
}
}
i0++;
}
}