program that prints itself

This is a discussion on program that prints itself within the C Programming forums, part of the General Programming Boards category; I guess someone has heard of the programs that when executed print their code like this one : Code: #include ...

  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    36

    program that prints itself

    I guess someone has heard of the programs that when executed print their code like this one :
    Code:
    #include <stdio.h>
    
    main()
    {
         char*p="main(){char*p=%c%s%c;printf(p,34,p,34,10);}%c";
         printf(p,34,p,34,10);
    }
    Can someone explain me how it works or post a link cause i can't get it.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,434
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Program Plan
    By Programmer_P in forum C++ Programming
    Replies: 0
    Last Post: 05-11-2009, 01:42 AM
  2. Can someome help me with a program please?
    By WinterInChicago in forum C++ Programming
    Replies: 3
    Last Post: 09-21-2006, 10:58 PM
  3. Need help with my program...
    By Noah in forum C Programming
    Replies: 2
    Last Post: 03-11-2006, 06:49 PM
  4. Replies: 4
    Last Post: 01-29-2002, 01:42 AM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21