There are two central concepts here:
printf() returns the number of characters printed.
- The
%*d format specifier causes printf() to read two integers from its arguments, and use the first to set the field width used to format the second (as a decimal number).
So in effect the values being added are used as field widths, and printf() then returns the sum.
I'm not sure about the actual d formatting of the space character, at the moment. That looks weird, I would have gone with an empty string instead:
static int sum(unsigned int a, unsigned int b)
{
return printf("%*s%*s", a, "", b, "");
}
int main(void)
{
unsigned int a = 13, b = 6;
int apb = sum(a, b);
printf("%d + %d = %d?\n", a, b, apb);
return 0;
}
The above works and properly computes the sum as 19.
char dummy; return snprintf(&dummy, 1, "%*s%*s", x, "", y, "");instead to avoid useless output.add. Then your question is about the functionsum. Those are different functions.