Code for producing its own source code.

char*s=”char*s=%c%s%c;main( ) { printf ( s, 34, s, 34 ) ; }”;

main( ) { clrscr( ) ;printf ( s, 34, s, 34 ) ; }

This is a classic example of self-reproducing program. Program that produces its own source code as its output.

(ASCII of double-quote character has the value 34.)

The first s in printf( ) prints the string ‘char *s =’ , then due to %c within s it prints double-quote character and then %s within the string prints the whole string then due to %c it prints doube-quote(34) for the second time and lastly remaining part of string after %c gets printed out.

This entry was posted in C Programming and tagged . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>