- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What are different format specifiers used in C language?
Format specifiers are used for input-output (I/O) operations. With the help of a format specifier, the compiler can understand what type of data is in I/O operation.
There are some elements that affect the format specifier. They are as follows −
A minus symbol (-): Left alignment.
The number after % specifies the minimum field width. If the string is less than the width, it will be filled with spaces.
Period (.) − Separate field width and precision.
Format specifiers
Here is the list of some format specifiers −
Specifier | Used for |
---|---|
%c | a single character |
%s | a string |
%hi | short (signed) |
%hu | short (unsigned) |
%Lf | long double |
%n | prints nothing |
%d | a decimal integer (assumes base 10) |
%i | a decimal integer (detects the base automatically) |
%o | an octal (base 8) integer |
%x | a hexadecimal (base 16) integer |
%p | an address (or pointer) |
%f | a floating point number for floats |
%u | int unsigned decimal |
%e | a floating point number in scientific notation |
%E | a floating point number in scientific notation |
%% | the % symbol |
Example
Given below is the C program for %o octal integer format specifier −
#include <stdio.h> int main() { int num = 31; printf("%o
", num); return 0; }
Output
When the above program is executed, it produces the following result −
37
Advertisements