chandanlinster said:
as i was going through the "printf" man page, i came across this
statement.
printf("%*d", width, num);
what does "*" mean?
Reread the man page, it is explained there
You have several things that can be found between the '%' and
the "conversion specifier", in this case 'd':
- flags (modify left-/right-justified and several other aspects)
- fieldwidth (how many characters are at least output)
- precision (various meanings)
- length modifier (e.g. 'l' which means in our example "long int
argument")
What you have here is the fieldwidth. This can be a number or
a '*'.
printf("%2d", num);
is equivalent to
printf("%*d", 2, num);
Advantage of the '*': You can determine the format at runtime.
Cheers
Michael