Try another example from KandR, I have the following C code:
#include <stdio.h>
int main(){
double nc = 5;
printf("%*.0f",nc);
return 0;
}
This prints 5, and then continues to move (print blank characters) from left to right, and then a new line until stopped by pressing Ctrl+ C). When I change the line printfto printf("%.0f",nc), it works as expected, that is, it just prints 5 and stops.
According to http://www.cplusplus.com/reference/cstdio/printf/ printf syntax:
% [flags] [width] [. precision] [length] specifier.
I changed [width]to *, so that printfdoes not limit the numbers at the output.
1) Why does he continue to print blank characters until he stops?
2) When I do not give any width, what does printfthe default mean ?
3) , nc = 500, printf , !
500.00, 500 . , nc=500 , nc=500.00?