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 8980841
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:11:13+00:00 2026-06-15T20:11:13+00:00

I have a simple program which is supposed to print a string. But I

  • 0

I have a simple program which is supposed to print a string. But I am not getting the expected output. Can anyone tell me what is wrong with the program ?

Here is my code:

main()
{
   char arr[] = "Test_string";
   printf("%20s"+1,arr);
   return 0;
}

output: 20s

Expected output is:Test_string

"Test_string" getting printed in 20 places as we are giving "%20s" as format specifier.

  • 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-06-15T20:11:15+00:00Added an answer on June 15, 2026 at 8:11 pm

    It is very simple if you carefully look at your printf call.

    Here is the prototype of printf : int printf(const char *format, ...);.

    printf expects a pointer to format string as the first argument. In your program you are passing a pointer to this string : "20s" and printf promptly prints what you are passing.

    Let me explain why the pointer passed is pointing to "20s" and not "%20s".

    Quoted strings in C are interpreted as character pointers.
    Character arrays which, when passed to a function, decay into a pointer.

    printf("%20s",arr); is equivalent to :

    const char * ptr = "%20s";
    printf(ptr,arr);
    

    similarly printf("%20s"+1,arr); is equivalent to :

    const char * ptr = "%20s";
    printf(ptr+1,arr);
    

    Because you are passing "%20s"+1, the actual pointer which is passed to printf is pointing to a string "20s".

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple program which is able to change the background color after
I have avery simple program which uses MediaPLayer. I am new to java and
Below, I have a simple program which uses the CImg library (http://cimg.sourceforge.net/) which iterates
I have a simple program (written in Java) which uses the google protocol buffer
I have a simple Delphi program that I'm working on, in which I am
I have been trying to create a simple program with Python which uses OpenCV
In my google maps program I have simple KML parser which retrieve only coordinates
I have a simple script which is used to start another program. This other
Suppose I have a simple program which takes argument input in one of the
I have an android program. It has a button which when clicked is supposed

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.