Printf Function

    1100448 VIEW 2 0

The printf() function are used for output in C language. printf function are inbuilt library functions, defined in stdio.h (header file).

The printf() function is used for output. It prints the given statement to the console.

The syntax of printf() function is given below:

printf("format string",argument_list);  
  •  %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.
  • %x for hexadecimal variable.
  • To generate a newline,we use “\n” in C printf() statement.

For Example:

#include 
int main()
{
   char ch = 'H';
   char str[15] = "Hyper Institute";
   float flt = 10.100;
   int no = 100;
   double dbl = 20.123456;
   printf("Character is %c \n", ch);
   printf("String is %s \n" , str);
   printf("Float value is %f \n", flt);
   printf("Integer value is %d\n" , no);
   printf("Double value is %lf \n", dbl);
   printf("Octal value is %o \n", no);
   printf("Hexadecimal value is %x \n", no);
   return 0;
}

Output

Character is H
String is Hyper Institute
Float value is 10.10
Integer value is 100
Double value is 20.123456
Octal value is 226
Hexadecimal value is 96