Yes , i got the point the last statement comes as it is the part of string literal.
Thanks & Regards, Aakanksha. ________________________________ From: Aakanksha Hulkur <[email protected]> To: [email protected] Sent: Thu, 12 November, 2009 11:44:29 AM Subject: Re: [c-prog] Re: please Help Thanks for the information. As far my understanding, the statement : printf (s, 34, s, 34); the first s prints the string till double quote i.e int main() { char *s = Now for 34 represented as character places " ,therefore int main() { char *s = " again %s, prints the entire string : int main() { char *s = "int main() { char *s = %c%s%c; printf(s,34,s, 34); now %, printing quote ": int main() { char *s = "int main() { char *s = %c%s%c; printf(s,34,s, 34); i am much confused here that how the next statement is printed i.e ; printf(s,34,s,34); Please, clarify me on this. Thanks & regards, Aakanksha ________________________________ From: Peter <[email protected]> To: [email protected] Sent: Thu, 12 November, 2009 8:06:01 AM Subject: [c-prog] Re: please Help --- In c-p...@yahoogroups. com, Aakanksha Hulkur <aakanksha_hulkur@ ...> wrote: > > [mod-- http://www0. us.ioccc. org/1994/ smr.hint --mod pn] > > Hi , > > Can anybody explain that how the below program works. What don't you understand? > Below is the quine.(program that prints out its own > source code). You've reformatted it so isn't a quine anymore. The program is meant to be a single line. > intmain() I suspect you meant int main(). Note that the lack of prototype declaration for the variadic function printf means the program's behaviour isn't actually defined. > { > char *s = "int main() { char *s = %c%s%c; printf(s,34, > s, 34);"; This declares a pointer to a string. > printf(s,34, s, 34); That string becomes the format string for a call to printf which, funilly enough, prints out something close to the source code. Note that 34 is the ASCII code for double quote ("). > } printf's first argument is a const char *. It doesn't have to be a string literal. A further technical note is that C99 added a restrict qualifier to printf... int printf(const char * restrict format, ...); ...which renders the (true) quine's behaviour further undefined. -- Peter ________________________________ The INTERNET now has a personality. YOURS! See your Yahoo! Homepage. The INTERNET now has a personality. YOURS! See your Yahoo! Homepage. http://in.yahoo.com/ [Non-text portions of this message have been removed]
