The Format specifier is a string used in the formatted input and output functions. The format string determines the format of the input and output.
The format string always starts with a '%' character.
Format specifier | Type |
---|---|
%d or %i | It's used to print the integer value(positive n negative both) |
%o | It’s used to print the octal value |
%x | It’s is used to print the hexadecimal integer value and it always starts with a 0x value.in this case, alphabetical characters are printed in small letters like a,b,c, etc. |
%X | It’s is used to print the hexadecimal integer value. but %X prints the alphabetical characters in uppercase like A, B, C, etc. |
%f | It’s is used for print the decimal floating-point values. |
%s | It’s used to print the strings. |
%c | It’s used to print the unsigned character. |
%ld | It is used to print the long-signed integer value. |
#include<stdio.h>
int main(){
int a =10;
printf("Value of a is:%d\n",a ); //Value of a is 10
return 0;
}
#include<stdio.h>
int main(){
int a =66;
printf("%o\n", a); //102
printf("%d\n", a); //66
return 0;
}
#include<stdio.h>
int main(){
int a =0xfc;
printf("%x\n", a); //fc
printf("%X\n", a); //FC
printf("%d\n", a); //252
return 0;
}
#include<stdio.h>
int main(){
float a = 3.14;
printf("%f", a); //3.140000
return 0;
}
#include<stdio.h>
int main(){
float a=3;
printf("%E", a); //3.000000E+00
return 0;
}
#include<stdio.h>
int main(){
char a='C';
printf("%c", a); //C
return 0;
}
#include<stdio.h>
int main(){
printf("%s", "prosequence.tech"); //prosequence.tech
return 0;
}