A challenge: how to write a program that outputs its own source code?

Source: Internet
Author: User
A challenge: how to write a program that outputs its own source code? Writing a portable self-regeneration program is difficult, in part because of the difficulty of referencing and character sets.

Here is a classic example (it should be represented in a line, although it is self-repaired after the first execution ):

Char * s = "char * s = % C % S % C; Main () {printf (S, 34, S, 34) ;}"; Main () {printf (S, 34, S, 34 );}

This program has some dependencies, ignoring # include <stdio. h>, and assuming double quotation marks"The value is 34, which is the same as the value in ASCII.

Here is another release of James HU:

# Define Q (k) Main () {return! Puts (# K "/NQ (" # K ")");} Q (# define Q (k) Main () {return! Puts (# K "/NQ (" # K ")");})

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.