You may notice that we used %d to print integer number but %f for fraction. This is called format specifier in C. There are different format specifier to print different data type. List of most used format specifier and example are given below:
Data type | Format specifier | Example |
---|---|---|
int | %d or %i |
#include<stdio.h> int main() { int variable; variable=25; printf("%d",variable); printf("%i",variable); return 0; } |
long int | %ld |
#include<stdio.h> int main() { long int variable; variable=25; printf("%ld",variable); return 0; } |
float | %f |
#include<stdio.h> int main() { float variable; variable=25.26; printf("%f",variable); return 0; } |
double | %lf |
#include<stdio.h> int main() { double variable; variable=25.365; printf("%lf",variable); return 0; } |
char | %c |
#include<stdio.h> int main() { char variable; variable='A'; printf("%c",variable); return 0; } |
Next Previous