+ 1
why we use %2d and %5s in c program
2 ответов
+ 8
1. "%2d" The '2' here specifies the field width, the 'd' specifies the value type was signed `int`. When the value has less than 2 digits, it will be printed with padding character to its left, to make the field width fits 2 characters. If the field width specifier was a negative value will be left aligned, otherwise it will be right aligned.
2. "%5s" The '5' also defines the field width, and the 's' specifies the value type was C-String (char array).
P.S. For more details, see this as reference:
http://www.cplusplus.com/reference/cstdio/printf/
Hth, cmiiw
+ 2
%2d stands for two digits number
%5s stands for five character string