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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:12:09+00:00 2026-06-17T20:12:09+00:00

Can someone please help me understand the following expression? printf(%3d – %s\n, counter, name)

  • 0

Can someone please help me understand the following expression?

printf("%3d - %s\n", counter, name)

That line prints something like this 6 - Install Adobe software

I have looked up information and read the reference but I can’t find a simple answer and I’m a bit confused. If you can refer me to a good reference, please do so.

%3d Ok, according to what I could understand, %3d is the number of characters or spaces. Please point me to a reference that explains it.

%s\n I couldn’t figure out what this does. I guess \n is a newline or something similar, but by looking at the output it doesn’t seem to work like that.

Why are counter and name variables separated by commas?

By looking at the output is seems that %3d is kind of replaced by counter and %s\n is replaced by name. I’m not sure how it works but I would like to understand it.

  • 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-17T20:12:10+00:00Added an answer on June 17, 2026 at 8:12 pm

    For syntax look at any printf docs, but check the sprintf docs on ruby-doc.

    They’re separated by commas because they’re separate parameters to the function, but that’s more or less syntactic sugar. Think varargs.

    Not sure what you mean with the %s\n thing, it’s a string then a newline: that’s what it outputs.

    If your question is specifically “how does the code turn a formatting string and a group of arguments into output” I’d probably search for source, for example, a tiny embedded printf. Nutshell version is that the format string is searched for formatting options, they consume their associated parameters, outputting an appropriately-formatted string. It’s a tiny little DSL.

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

Sidebar

Related Questions

Can someone please help me understand the following: In the previous version of NHibernate
Can someone please help me to understand this following partial parallel sum algorithm implementation
Java docs says the following about Set interface, can someone please help me understand
Can someone please help me figure out a way to achieve the following (see
Please can someone help? I have the following code which uploads a file to
Can someone please help be take apart the elements here and help me understand
With real examples and their use, can someone please help me understand: How to
Can someone please help me understand how to setup the connectionString and the InternetURL
Could someone please help me to understand why the following block of code keeps
Can someone please help me understand how I would write this. If i am

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.