Re: How to understand this line of c ?



"lnzju" <geniuslee@xxxxxxxxx> wrote:
>main(_){for(--_;putchar(_++["J!Mpwf!Zpv\1"]-1););}

The two following code fragments are equivalent:

/*-A-----------------------------------*/

#include <stdio.h>

int main(void)
{
char rubbish[] = "J!Mpwf!Zpv\1"; /* will 'print' trailing '\0' */
char *rp = rubbish;

while (*rp)
{
putchar ((*rp)-1);
rp++;
}
putchar('\n'); /* not in original code */
}

/*-B-----------------------------------*/

#include <stdio.h>

int main(void)
{
char rubbish[] = "I Love You\0"; /* '\0' is redundant here */
char *rp = rubbish;

while (*rp)
{
putchar(*rp);
rp++;
}
putchar('\n'); /* not in original code */
}

/*-------------------------------------*/
.



Relevant Pages