--- In [email protected], Aakanksha Hulkur <aakanksha_hul...@...> 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