0% found this document useful (0 votes)
34 views10 pages

Comments

The document discusses format specifiers and escape sequences used in C printf function. It covers integer, floating point and string format specifiers along with flags, field width and precision. It also covers common escape sequences like newline, tab, backspace etc.

Uploaded by

creatorvision
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views10 pages

Comments

The document discusses format specifiers and escape sequences used in C printf function. It covers integer, floating point and string format specifiers along with flags, field width and precision. It also covers common escape sequences like newline, tab, backspace etc.

Uploaded by

creatorvision
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 10

Comments main() { /* this program is for calculating the sum Of two numbers using the arithmetic operator */ int

a,b,c; // here I am declaring the variables scanf(%d%d,&a,&b); //getting inputs c=a+b; printf(%d,c); }

Format Specifiers Type-identifiers The type-identifiers are as follows:


d, i Signed integers o Unsigned integers displayed in octal

form.
u Unsigned integers in decimal form. x Unsigned integers in hexadecimal form,

and the hexadecimal characters a, b, c, d, e, and f printed in lowercase.


X Unsigned integer in hexadecimal form,

and the hexadecimal characters A, B, C, D, E, and F printed in uppercase.


c Any value converted to unsigned char and displayed; c is used mainly for

printing characters.
s String

f Floating point. e, E Floating point displayed in

exponential form. one digit to the left of the decimal point; right side of the decimal point depends on the required precision.

Field-width
1.

Field-width indicates the least number of columns that will be allocated to the output.

Printf(%4d,a);
if value of a is 10 >>>bb10
2.

if a is 12345 then 5 columns are used, even if %4d is specified. In any circumstance, the output width is not shortened, because of fieldwidth. If you specify * instead of field-width then you have to specify additional arguments.

3.

4.

printf ("%*d\n", 5, a); >>> a is printed in 5 cols

printf ("%*d\n", 20, a); >>> a is printed in 20 cols

Precision
1.

Precision indicates the minimum number of digits printed for type integers d, i, o, u, x, and X.

For example,
printf("%10.4d\n", 35); o/p - bbbbbb0035 printf(10.4f,3.5); o/p - bbbbb3.5000

Flags
printf("%-10.4d\n", 25)

It causes the number to be printed as 0025bbbbbb. Thus, blanks are added to the right side. In the absence of a flag, it is printed as bbbbbb0025.
+ Indicates that i number is printed using a sign character (+ or ). printf("%+d\n", -25);>>> -25 printf("%+d\n", 25); >>> +25

# to display the output in another form Printf(%-9x,i); if i== 7c, it prints 0x7c

%9f floating point will definitely have a decimal point

Escape Sequence
\a Alert - Produces a beep or flash; the

cursor position is not changed.


\b Backspace - Moves the cursor to the

last column of the previous line.


\f Form feed - Moves the cursor to start

of next page.
\n New line - Moves the cursor to the

first column of the next line.


\r Carriage Return - Moves the cursor to

the first column of the current line.


\t Horizontal Tab - Moves the cursor to

the next horizontal tab stop on the line.


\v Vertical Tab - Moves the cursor to the

next vertical tab stop on the line.

\\ - Prints \\
\" - Prints "

%% Prints %.

You might also like