0% found this document useful (0 votes)
8 views2 pages

Format Specifiers

Uploaded by

The ᎪsuᏒᎪ
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

Format Specifiers

Uploaded by

The ᎪsuᏒᎪ
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Format Specifiers are used to indicate the type of data to be input or output.

It tells the compiler how to interpret the data (e.g., as an integer, float, or string).

1. Integers

 %d: Signed decimal integer.


 %i: Signed decimal integer (alternative to %d).
 %u: Unsigned decimal integer.

2. Floating-point numbers

 %f: Decimal floating-point (e.g., 3.14).


 %lf: Used for double type (in scanf()).

3. Strings and Characters

 %s: String of characters (null-terminated).


 %c: Single character.

4. Floating-point (Alternative Representations)

 %e: Scientific notation (lowercase, e.g., 1.23e+03).


 %E: Scientific notation (uppercase, e.g., 1.23E+03).
 %g: Shortest representation between %f and %e.
 %G: Same as %g, but uses %E if the exponent is large.

5. Hexadecimal and Octal

 %x: Unsigned hexadecimal (lowercase letters a to f).


 %X: Unsigned hexadecimal (uppercase letters A to F).
 %o: Unsigned octal.

6. Pointers and Memory Addresses

 %p: Pointer (memory address in hexadecimal format).

7. Long Integers

 %ld: Signed long integer.


 %lu: Unsigned long integer.

8. Long Long Integers

 %lld: Signed long long integer.


 %llu: Unsigned long long integer.
9. Short Integers

 %hd: Signed short integer.


 %hu: Unsigned short integer.

10. Special Characters and Literals

 %%: Prints a literal % sign.


 \n: Newline character (used within strings for line breaks).
 \t: Tab character (used within strings for tabs).

11. Wide Characters and Strings (for Unicode support)

 %lc: Wide character (e.g., wchar_t type).


 %ls: Wide string (e.g., wchar_t[]).

12. Size-Specific Modifiers

 %hhd: Signed char.


 %hhu: Unsigned char.
 %zd: size_t type for signed integers.
 %zu: size_t type for unsigned integers.

13. Floating-Point in Hexadecimal

 %a: Hexadecimal floating-point (lowercase).


 %A: Hexadecimal floating-point (uppercase).

14. Signed or Unsigned Differences (Short and Long Variants)

 %hi: Short signed integer (same as %hd).


 %li: Long signed integer (same as %ld).

You might also like