Thread: program that prints itself

  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 int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    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.

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, 07:49 PM
  4. Replies: 4
    Last Post: 01-29-2002, 02:42 AM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM