Skip to main content

Output for given format specifiers

Short answer

printf("[%10i]",456); yields [ 456] (right-aligned). printf("[%3c]",'A'); yields [ A]. printf("[%-10.3f]",3.14159); yields [3.142 ] (left-aligned). printf("[%x]",255); yields [ff] (hex).

Give suitable example with sample output for the following: %10i, %3c, %-10.3f and %x.

Each specifier is shown between brackets so the spaces can be seen.

#include <stdio.h>
int main(void)
{
    printf("[%10i]\n", 456);
    printf("[%3c]\n", 'A');
    printf("[%-10.3f]\n", 3.14159);
    printf("[%x]\n", 255);
    return 0;
}

Output:

[       456]
[  A]
[3.142     ]
[ff]
SpecifierMeaningResult for the example
%10iinteger in a field 10 wide, right aligned[ 456] (7 blanks, then 456)
%3ccharacter in a field 3 wide, right aligned[ A]
%-10.3ffloat with 3 decimals, left aligned in width 10[3.142 ]
%xinteger in lowercase hexadecimal[ff] for 255

✓ Answer checked by Claude Opus 5.5 (high effort)

All Computer Programming chapter 4 questions →