Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6646319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:24:07+00:00 2026-05-26T00:24:07+00:00

I came across a program that prints itself on this site, i.e. it prints

  • 0

I came across a program that prints itself on this site, i.e. it prints the program code.

The program code is:

#include <stdio.h>
char *program = "#include <stdio.h>%cchar *program = %c%s%c;%cint main()%c{%cprintf(program, 10, 34, program, 34, 10, 10, 10, 10, 10, 10);%c    return 0;%c}%c";
//what is this line doing, what is the use of %c and %s and what properties of %c and %s are being used here?
int main()
{
        printf(program, 10, 34, program, 34, 10, 10, 10, 10, 10, 10);
        //what is this print function doing, and how?
        return 0;
}

And the explanation given is:

The two key tricks here are using a string with an embedded %s
specifier to allow the string to contain itself when printed, and to
use the %c format specifier to allow printing out special characters
like newlines, which could not otherwise be embedded in the output
string.

I didn’t understand how the program is working. I have mentioned the lines i need the explanation about, how they work and what are they doing. Please explain.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T00:24:08+00:00Added an answer on May 26, 2026 at 12:24 am
    char *program = "#include <stdio.h>%cchar *program = %c%s%c;%cint main()%c{%cprintf(program, 10, 34, program, 34, 10, 10, 10, 10, 10, 10);%c    return 0;%c}%c";
    

    There is a char pointer name “program” which is used to store the string and %c and %s are format specifiers for char and string arguments respectively.

    printf(program, 10, 34, program, 34, 10, 10, 10, 10, 10, 10);
    

    printf function is printing output to console, 10 here is ASCII code for NEWLINE and 34 for ”
    printf parameters are doing

    • program , passing string to be printed
    • 10 , passing 10 ASCII code for first %c (will be converted to character newline)
    • program , passing same string again to %s in program to print same string again
    • 34 , passing 34 ASCII code for second %c (will be converted to character double qoutes)
    • 10 , passing 10 ASCII code for 3rd %c (will be converted to character newline)
    • 10 , passing 10 ASCII code for 4th %c (will be converted to character newline)
    • 10 , passing 10 ASCII code for 5th %c (will be converted to character newline)
    • 10 , passing 10 ASCII code for 6th %c (will be converted to character newline)
    • 10 , passing 10 ASCII code for 7th %c (will be converted to character newline)
    • 10 , passing 10 ASCII code for 8th %c (will be converted to character newline)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I came across a controller in an older set of code (Rails 1.2.3) that
I just came across a bug in my program, that has me confused. I
There is a calculator program that I have came across on Windows long ago.
I came across this code http://support.microsoft.com/kb/320348 which made me wonder what would be the
I have been experimenting with GNU Radio and came across the tunnel.py program. This
I was going through some code examples and came across this application which which
I came across a interview question that asked to remove the repeated char from
I came across this scenario. We have a class lets say Main having a
I'm reading my Deitel, Java How to Program book and came across the term
I came across this term - Quine (also called self-reproducing programs). Just wanted to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.