Couldn't find it either googling it or in the lectures so far. Does somebody have the complete options and what they are for? Thank you very much.


printf formatting is a language unto itself. This document helped me a lot. Hope you find it useful.

  • Thank you very much, I'll make good use of the document you posted, hopefully. – 333PPP Aug 19 '20 at 16:47

These characters are used as "wildcards" or placeholders. They are used in conjunction with something like printf().

Very basic example //declaring an int variable to a value of 5 int x = 5;

//printing "%i" using the value of X printf("%i", x);

Result would print: 5

This is because printf is accepting 2 parameters here. When you use "%i", it then expects the user to pass another parameter, to replace this placeholder that was initially given. They are used because the value of x will not ALWAYS be 5 in an example program, so instead of saying printf("5"), it will now print whatever value is given to the second parameter, in this case X.

More complex but practical example a program is used to post a group of orders but if there is an error, tell the user which order needs to be fixed.

if (some error occurs) printf("Order %i could not be posted.", CurrentOrderNumber)

result: Order 2352 could not be posted

In this case as it looped through the orders trying to post them, order 2352 produced an error, so this will replace %i, with the CurrentOrderNumber. By doing so all orders with errors will be printed and the user will know which order needs to be fixed

  • Thank you very much, it's much clearer now. – 333PPP Aug 19 '20 at 16:46
  • 1
    sorry my formatting sucked but glad i was able to clear it up a bit for you! – adgrutta Aug 19 '20 at 16:58
  • Both our fellow coder and you gave me cool answers. I'm sorry I can only mark one answer as helpful because yours was, and understandably formatted. So yes, and thank you. – 333PPP Aug 19 '20 at 23:39

You must log in to answer this question.

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