---
title: "Output for given format specifiers"
subject: "Computer Programming"
chapter: 4
key: "semester_1/computer_programming:format-specifiers-sample-output"
source: https://www.bctengineer.com/q/semester_1/computer_programming/format-specifiers-sample-output
site: BCT Engineering
---

# Output for given format specifiers

Computer Programming · Chapter 4: Input and Output

- Asked in: 2072 Kartik, 4 marks
- Video: [Formatted Output in C using printf (Width, Precision & Flags) || Lesson 39 || C Programming ||](https://www.youtube.com/watch?v=xvXBiXyxohM) — Wisdomers - Computer Science and Engineering 
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_1/computer_programming/format-specifiers-sample-output
- Whole chapter: https://www.bctengineer.com/md/semester_1/computer_programming/chapter-4

## Question

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

## 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).

## Answer

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

```c
#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:
```text
[       456]
[  A]
[3.142     ]
[ff]
```

| Specifier | Meaning | Result for the example |
|---|---|---|
| `%10i` | integer in a field 10 wide, right aligned | `[       456]` (7 blanks, then 456) |
| `%3c` | character in a field 3 wide, right aligned | `[  A]` |
| `%-10.3f` | float with 3 decimals, left aligned in width 10 | `[3.142     ]` |
| `%x` | integer in lowercase hexadecimal | `[ff]` for 255 |

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. printf("[%10i]", 456) prints:
   A. [456       ]
   B. [       456]
   C. [0000000456]
   D. [456]
   Answer: B. Width 10, right aligned: 7 blanks and 456. (Key point: %10i)

2. printf("[%3c]", 'A') prints:
   A. [A  ]
   B. [  A]
   C. [A]
   D. [ A ]
   Answer: B. Width 3, right aligned, so two blanks before A. (Key point: %3c)

3. printf("[%-10.3f]", 3.14159) prints:
   A. [3.142     ]
   B. [     3.142]
   C. [3.14159   ]
   D. [3.141     ]
   Answer: A. 3 decimals rounds to 3.142; the minus left-aligns in width 10. (Key point: %-10.3f)

4. printf("[%x]", 255) prints:
   A. [255]
   B. [FF]
   C. [ff]
   D. [0xff]
   Answer: C. %x prints lowercase hexadecimal: ff. (Key point: %x)

## Related in Computer Programming

- [Correct program: do-while and pow](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Acorrect-program-sum-root) — Computer Programming, chapter 3
- [Correct program: case array and average](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Acorrect-program-case-array) — Computer Programming, chapter 3
- [RECORD.txt item cost with VAT](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Afile-record-txt-invoice) — Computer Programming, chapter 10

## Related in other subjects

- [Sample mean income of 10 retailers](https://www.bctengineer.com/question.md?key=semester_5%2Fprobability_and_statistics%3Aretailers-income-sample-10) — Probability and Statistics, chapter 4
- [Clay 10 m, 2.54 cm sample, half settlement](https://www.bctengineer.com/question.md?key=semester_4%2Fsoil_mechanics%3Aclay-10m-half-settlement-time-ratio) — Soil Mechanics, chapter 9
- [Theodolite traverse ABCDA, booking format with VCR](https://www.bctengineer.com/question.md?key=semester_3%2Fsurveying_i%3Atraverse-abcda-booking-format-vcr-120-14-20) — Surveying I, chapter 7
- [Sample mean, variance, CV: patients' sleep hours](https://www.bctengineer.com/question.md?key=semester_5%2Fprobability_and_statistics%3Ahospital-patients-sleep-mean-cv) — Probability and Statistics, chapter 1, asked 3×
