xxxxxxxxxx
Format Specifiers
In C programming language, %d and %i are format specifiers as where %d specifies the type of variable as decimal and %i specifies the type as integer. In usage terms, there is no difference in printf() function output while printing a number using %d or %i but using scanf the difference occurs. scanf() function detects base using %i but assumes base 10 using %d.
xxxxxxxxxx
%[flags][width][.precision][length]specifier
specifiers:
c: char
d or i: signed decimal integer
e: scientific notation (using 'e' character)
E: scientific notation (using 'E' character)
f: decimal floating point
g: uses shorter one of e or f
G: uses shorter one of E or f
o: signed octal
s: string of chars
u: unsigned decimal integer
x: unsigned hexadecimal integer
X: unsigned hexadecimal integer (uppercase)
P: pointer address
n: nothing printed
%: use '%%' to print '%'
flags:
-: left justify (right justification is default)
+: show + or - depending on sign
' ' (space): no sign
#: with %o, %x, or %X, put 0, 0x, or 0X in front of value
#: with %e, %E, or %f, force decimal point
#: with %g, or %G, same as %e or %E but trailing zeroes are not removed
0: left-pad with 0's
width:
(number): min characters to be printed, pad with spaces by default
doesn't truncate
*: an additional argument preceding the value is used to specify the width
.precision similar to width
length:
h: short int or unsigned short int
l: long int or unsigned long int
L: long double
sourced from
https://www.tutorialspoint.com/c_standard_library/c_function_printf.htm
xxxxxxxxxx
#include<stdio.h>
void main(){
printf("My name is MD Fuadul Islam Redoy\n");
printf("My birthday date is 4 April 2000\n");
printf("My mobile number = 01621025110\n");
}
xxxxxxxxxx
PRINTF() FUNCTION IN C LANGUAGE:
In C programming language, printf() function is used to print the (“character, string, float, integer, octal and hexadecimal values”) onto the output screen.
We use printf() function with %d format specifier to display the value of an integer variable.
Similarly %c is used to display character, %f for float variable, %s for string variable, %lf for double and %x for hexadecimal variable.
To generate a newline,we use “\n” in C printf() statement.
xxxxxxxxxx
Format Specifiers
In C programming language, %d and %i are format specifiers as where %d specifies the type of variable as decimal and %i specifies the type as integer. In usage terms, there is no difference in printf() function output while printing a number using %d or %i but using scanf the difference occurs. scanf() function detects base using %i but assumes base 10 using %d.