Format specifiers
The format specifiers are used in C for input and output purposes. By using this compiler can easily understand that what type of data is in a variable during taking input using the scanf() function and printing using printf() function.
List:
Format Specifier |
Type |
%c |
Character |
%d |
Signed integer |
%e or %E |
Scientific notation of floats |
%f |
Float values |
%g or %G |
Similar as %e or %E |
%hi |
Signed integer (short) |
%hu |
Unsigned Integer (short) |
%i |
Unsigned integer |
%l or %ld or %li |
Long |
%lf |
Double |
%Lf |
Long double |
%lu |
Unsigned int or unsigned long |
%lli or %lld |
Long long |
%llu |
Unsigned long long |
%o |
Octal representation |
%p |
Pointer |
%s |
String |
%u |
Unsigned int |
%x or %X |
Hexadecimal representation |
%n |
Prints nothing |
%% |
Prints % character |
Example:
#include <stdio.h>
int main()
{
char ch = 'S';
int no_1 = 25, no_2 = 70;
float no_3 = 12.67;
int no_4 = 67;
printf("%c\n", ch); //printing character data
printf("%d\n", no_1); //print decimal
printf("%i\n", no_2); //print integer data
printf("%f\n", no_3); //print float value
printf("%e\n", no_3); //print in scientific notation
printf("%o\n", no_4); //print in octal format
printf("%x\n", no_4); //print in hex format
return 0;
}
int main()
{
char ch = 'S';
int no_1 = 25, no_2 = 70;
float no_3 = 12.67;
int no_4 = 67;
printf("%c\n", ch); //printing character data
printf("%d\n", no_1); //print decimal
printf("%i\n", no_2); //print integer data
printf("%f\n", no_3); //print float value
printf("%e\n", no_3); //print in scientific notation
printf("%o\n", no_4); //print in octal format
printf("%x\n", no_4); //print in hex format
return 0;
}
Comments
Post a Comment