![]() |
How to understand this line of c ?
main(_){for(--_;putchar(_++["J!Mpwf!Zpv\1"]-1););}
|
Re: How to understand this line of c ?
"lnzju" <geniuslee@gmail.com> wrote in message
news:1136051664.299850.274430@g43g2000cwa.googlegr oups.com... > main(_){for(--_;putchar(_++["J!Mpwf!Zpv\1"]-1););} > Don't. It's rubbish. -- Ivan Budiselic ICQ# 104044323 IRC: buda @ #gamer.hr@quakenet remove 'remove' for reply |
Re: How to understand this line of c ?
lnzju wrote:
> main(_){for(--_;putchar(_++["J!Mpwf!Zpv\1"]-1););} Some hints: * Write the program with the correct tabulation * Take into account that usually main parameters are argc and argv, but they can be called with any name. And, if type is not declared K&R assumes int. * _ can be the name of a variable. * Split "for" in its parts: a for statement is divided in initialization, continue condition and update of state. The first one and third ones can be empty. * putchar returns the character written as unsigned int * integer applied to string returns n-th element. (this is something I do not know why). Kind regards. |
Re: How to understand this line of c ?
Ivan Budiselic wrote:
> "lnzju" <geniuslee@gmail.com> wrote in message > news:1136051664.299850.274430@g43g2000cwa.googlegr oups.com... >> main(_){for(--_;putchar(_++["J!Mpwf!Zpv\1"]-1););} >> > > Don't. It's rubbish. > > Well it ain't rubbish cause it is valid C!! Try compiling it.. The output will be: I Love You But this code is obfuscated.... Only the real C gurus will understand it I Guess.... not this novice guy... Broeisi |
Re: How to understand this line of c ?
Even when "gcc" compiled with the flags -ansi and -pedantic, it
produces no errors nor warnings. Only with -std=c99 it produces 3 warnings. |
Re: How to understand this line of c ?
Broeisi wrote:
> Ivan Budiselic wrote: > >> "lnzju" <geniuslee@gmail.com> wrote in message >> news:1136051664.299850.274430@g43g2000cwa.googlegr oups.com... >>> main(_){for(--_;putchar(_++["J!Mpwf!Zpv\1"]-1););} >>> >> Don't. It's rubbish. > > Well it ain't rubbish cause it is valid C!! Actually, it's not. In C main either takes no arguments or two arguments, not 1. > Try compiling it.. > > The output will be: > > I Love You Not necessarily. It was written assuming ASCII, and not all C implementations use ASCII. > But this code is obfuscated.... Only the real C gurus will understand it > I Guess.... not this novice guy... Depends. It's not that difficult. Just format it properly and learn a couple of tricks and it is simple. -- Flash Gordon Living in interesting times. Although my email address says spam, it is real and I read it. |
Re: How to understand this line of c ?
"Broeisi" <broeisito@gmail.com> wrote in message
news:Q-CdnbFfZLrCSCvenZ2dnUVZ8qSdnZ2d@casema.nl... > Ivan Budiselic wrote: > >> "lnzju" <geniuslee@gmail.com> wrote in message >> news:1136051664.299850.274430@g43g2000cwa.googlegr oups.com... >>> main(_){for(--_;putchar(_++["J!Mpwf!Zpv\1"]-1););} >>> >> >> Don't. It's rubbish. >> >> > > Well it ain't rubbish cause it is valid C!! > Try compiling it.. > > The output will be: > > I Love You Maybe on your machine. Certainly not on all. > But this code is obfuscated.... Only the real C gurus will understand it > I Guess.... not this novice guy... > There's nothing guruesque about it. -- Ivan Budiselic ICQ# 104044323 IRC: buda @ #gamer.hr@quakenet remove 'remove' for reply |
Re: How to understand this line of c ?
"lnzju" <geniuslee@gmail.com> wrote in message news:1136051664.299850.274430@g43g2000cwa.googlegr oups.com... > main(_){for(--_;putchar(_++["J!Mpwf!Zpv\1"]-1););} Here it is a little clearer [hopefully?] #include <stdio.h> // x will be 1 (the name of this app would be in argv[0]) if we // don't invoke the app with some args. // main(x) { char c; // zero then! // --x; while(c = "J!Mpwf!Zpv\1"[x]) { // No need for the -1 if we add 1 to the literal's characters... // // "I Love You\1" // c = c - 1; x++; putchar(c); } } |
Re: How to understand this line of c ?
"lnzju" <geniuslee@gmail.com> wrote in message news:1136051664.299850.274430@g43g2000cwa.googlegr oups.com... > main(_){for(--_;putchar(_++["J!Mpwf!Zpv\1"]-1););} > Ah, but run it with some params, and it's dissapointing. Perhaps the initialiser in the for loop would have been better this way? for(_^=_; putchar(_++["J!Mpwf!Zpv\1"]-1); ); |
Re: How to understand this line of c ?
"lnzju" <geniuslee@gmail.com> 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 */ } /*-------------------------------------*/ |
| All times are GMT. The time now is 11:47 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.