tags:

views:

53

answers:

1

Hi, in C if I have a printf statement containing say "%.2f", it says that the precision is 2 digits after the decimal place. I haven't explicitly specify the width. I have two questions:

  1. Is this good programming practice?;

  2. Is without specifying the width means that the width of the field will get adjusted automatically when printing the number, irrespective of the number of digits it contains?

Thanks a lot...

+1  A: 
  1. If this does what you want to do, then it's good practice. If it does something that you don't want to do, it's bad practice. Simple as that.

  2. Yes, the width is adjusted to fit the number. (Note that the width, if you specify it, is a minimum only; if you specified a width and the number wouldn't fit, the result would become wider than you might have expected.)

Thomas
Thanks. I've seen it somewhere that the width can be excluded but I don't remember where.
yCalleecharan