| |
|
Format Specifier C
Format specifier is string which is used in formatted input and output functions. And we use format string determines the format of input and output. Format string always starts with a "%" character.
Below are the most commonly used format specifiers in and printf() and scanf() function are given below.
Example for Format Specifier
(1)Use of %d in C program
In above example we use %d to print integer value of x and y
Output:-
Value of x is:2
Value of y is:4
(2)Use of %u in C program
In above program we use %u to display value of x and y by using unsigned format specifier. Here value of x is positive and for negative value it not print value of c and will change the value of -10.
Output:-
Value of x is:10
Value of y is:4294967286
(3)Use of %o in C program
In above program we will get value of octal and integer for a specific common value.
Output:-
Octal Value of x is:100
Integer Value of x is:64
(4)Use of %X and %x in C program
In above code y contains the hexadecimal value "A" and it is shown in two format one is "a" and another is "A" which is smaller and capital X. ANd when we use %d then it is shown in integer values.
Output:-
Hexadecimal Value of y is:a
Hexadecimal Value of y is:A
Integer Value of y is:10
(5)Use of %f in C program
In above code will print value of y as floating upto 6 characters
Output:-
Floating point value of y is: 3.400000
(6)Use of %e in C program
In above code output will be exponent part will be print
Output:-
Exponential value of y is: 3.000000e+00 | |
|
|
|
|