Iam currently working on pset1 mario .when i used printf(" "); to print spaces before hash it didn't work as expected.but then i used printf("%s"," ") it works now .what is the reason behind this?


They should work exactly the same. printf(" "); will print a single space, the content between the double quotes. printf("%s"," ") will grab the first parameter " "after the format string, "%s" and substitute it in for the placeholder %s. While the mechanism is a little different, it has the same result of printing a single space.

I am suspicious about why the first method wasn't working. If you had used single quotes instead of double quotes, it wouldn't have compiled. It really depends on exactly what the code was, both the printf and the surrounding code.

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

  • Do you have an idea in term of efficiency? From Syntax both should have similar behaviour but which one is more preffered?
    – Wafeeq
    Jun 23 '16 at 7:05
  • I would use the first.
    – Cliff B
    Jun 23 '16 at 7:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .