Question: What is the use of width in the `printf()` statement? Why is the output 7 in the example below?

### Code

```
int add(int x, int y)
{
    return printf("%*c%*c",  x, '\r',  y, '\r');
}

int main()
{
    printf("Sum = %d", add(3, 4));
    return 0;
}

```

### Output

> 
> Sum = 7
> 
> 
>

Answer: 
Consulting any [manual](http://linux.die.net/man/3/printf) shows that `printf` returns the number of characters that were printed, excluding the null terminator. `%*c` takes *two* arguments, the first being the field width (which is thus respectively 3 and 4), and the second being the actual character printed. In this case, the character is a carriage return (`\r`), which you probably can't see on your terminal. Since the two characters are printed with padding, a string of length 7 is printed, and 7 is returned.

Since you can't tell that spaces and carriage returns, it looks like nothing is printed at all -- try piping the output into a file or `hexdump`, though.
printf returns the number of characters printed. In this case you are printing 7 characters by specifying x and y as output lengths. If you change the return statement to:

```
return printf("%*c%*c\n",  x, '\r',  y, '\r'); 

```

The output will be 8, since a new line is also printed.