+ 1

why we use %2d and %5s in c program

14th Feb 2019, 3:44 AM
DEBASIS MOHARANA
DEBASIS MOHARANA - avatar
2 Antworten
+ 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
14th Feb 2019, 6:47 AM
Ipang
+ 2
%2d stands for two digits number %5s stands for five character string
14th Feb 2019, 6:46 AM
Maneren
Maneren - avatar