Sunday, November 7, 2010

Online Study

You need to remember the following rules for format specification:

1. The general syntax is %[arg_index$][flags][width][.precision]conversion char

2. A format specification must start with a % and end with a conversion char ( b boolean, c char,  d integer, f floating point, and s string). Anything before a % and after the conversion character is printed as it is. For example, printf("xxx%1$dyyy%2$dzzz", 10, 20) will be print xxx10yyy20zzz. Arg-index, flags, width, and .precision are all optional.

3. You need to remember the following flags:
"-" Left justify this argument - Must specify width as well.
"+" Include a sign (+ or -) with this argument - Applicable only if conversion char is d or f (i.e. for numbers).
"0" Pad this argument with zeroes  - Applicable only if conversion char is d or f (i.e. for numbers). Must specify width as well.
"," Use locale-specific grouping separators (i.e., the comma in 123,456)  - Applicable only if conversion char is d or f (i.e. for numbers).
"(" Enclose negative numbers in parentheses  - Applicable only if conversion char is d or f (i.e. for numbers).
_______________________________________________

No comments:

Post a Comment