Skip to main content

C Format Specifiers

Format Specifiers are used to display standard input and output value to console. Generally printf() and scanf() function are used to input and output purpose. Inside of this functions, format specifier are provide the information to compiler which kind of input value are retrieves and what type of value are display.

Format Specifiers

Note that when we define constant strings of that function there are no need to define its type. Format specifier is work on variables and constant literals. Here given list of all format specifiers in C programming.

Specifiers Overview
%c for single character
%d For integer variable. use to both signed and unsigned
%f for floating point variable
%lf , %E for double variable
%s for display strings
%i for signed integer
%p for display address of variables
%Lf for long double
%x , %X for Hexadecimal representation
%o for octal representation
%hi for short int (Signed integer)
%hu for unsigned short int
%li , %ld for long int (Signed integer)
%lld, %lld for long long int (Signed integer)
%llu for unsigned long long int

For example

//Use integer access specifiers
int main(){
  int year=2019;  
  unsigned int age=21;
  short int days=31;
  long long int total_seconds=23330000000;
  long int total_status=68922444;
  printf("year : %d",year); //signed integer
  printf("\nage : %i",age); //unsigned int 
  printf("\ndays : %hi",days); //short int
  printf("\ntotal_seconds : %lld",total_seconds); //long long int
  printf("\ntotal_status : %ld",total_status); //long int
  return 0;

Similar way we can use other access specifier to display associative data type.


Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.

New Comment