printf returns the number of characters printed.
printf("%*c", N, C); prints N-1 spaces followed by C.
In general, printf prints N - length_of_text spaces (if it is a number > 0 , zero spaces otherwise), followed by text. The same goes for numbers.
so
return printf("%*c%*c", x, ' ', y, ' ');
prints a space with the prefix x minus length_of_space in other spaces ( x-1 ), then does the same for y . This makes 4+5 spaces in your case. printf then returns the total number of characters printed, 9.
printf("%d",add(4,5));
This printf prints the integer returned by add() , 9.
By default, printf is right-aligned (spaces in front of the text). To make it left aligned, either
- enter negative
N or - add
- before * , for example. %-*s , or - the static version works, for example.
%-12s , %-6d
source share