-3

Why the following program work ? & what is difference b/w %d vs %*d ?

#include<stdio.h>

int main()
{
  int n=5;
  printf("n=%*d\n", n, n);

  return 0;
}

What does width meant here by ?

Mohit Jain
  • 30,259
  • 8
  • 73
  • 100
  • 3
    This question should be answered by looking into the documentation, not by asking an online community. That's basic research. – M Oehm Mar 14 '16 at 11:50
  • Why bother with searching documentation yourself if you can get an army of SO drones to do it for you at no cost? Why put more effort into an assignment than you need to? If a group of people are daft enough to do all your work for you, why not take advantage of it? – Martin James Mar 14 '16 at 12:00

1 Answers1

2

The first n belongs to the * in %*d, so for your example it is %5d. %5d means to print an integer of width 5. Example: 234 is printed as __234 (2 spaces)

Lincoln Cheng
  • 2,263
  • 1
  • 11
  • 17