what dose printf("%5d\n",3); do?

dose it print the number 3 five times or

dose it print the number 5 three times

also what dose printf("%d\n",3,5); do?

Comments

  • D Shah's answer is incorrect.

    printf("%5d\n",3); will print the number 3 as a decimal number, using 5 positions in the output. In other words, if the number that you're printing (3 in this case) consists of less than 5 digits, the digits that make up the number will be padded (at the beginning) using spaces.

    To get D Shah's output, you'd need to write this:

    printf("%05d\n",3);

    Note the zero before the digit 5.

  • printf(%5d\n",3) will print "00003" (%5d = number in decimal and in 5 digits)

    printf(%d\n",3,5) will print "3" only.

Sign In or Register to comment.