C Programming Language

printf

               The usually used output statement is printf (). It is one of the library functions.

Syntax : printf (“format string”, argument list);

              Format string may be a collection of escape sequence or/and conversion specification or/and string constant. The format string directs the printf function to display the entire text enclosed within the double quotes without any change.

Escape sequence:

                 Escape sequence is a pair of character. The first letter is a slash followed by a character. Escape sequence help us to represent within the format string invisible and non-printed character although there are physically two characters in any escape sequence. It actually represents only one. The various escape sequences are

  Escape sequence     Meaning  
  \n     New line  
  \t     Tab  
  \b     Back space  
  \a     Bell  
  \o     Null character  
  \?     To print question mark  
  \\     To print slash  
  \'     To print single quote  
  \"     To print double quote  

Conversion specification:

                Conversion specification is also a pair of character. it is preceded by  % and followed by a quote which may be a character. The Conversion specification inscribes the printf() function that it could print some value at that location in the text. The Conversion characters supported by C are

  Conversion character     Meaning  
  %d     Data item is displayed as a signed decimal integer.  
  %i     Data item is displayed as a single decimal integer.  
  %f     Data item is displayed as a floating-point value without an exponent.  
  %c     Data item is displayed as a single character.  
  %e     Data item is displayed as a floating-point value with an exponent.  
  %g     Data item is displayed as a floating-point value using either e-type or f-type conversion depending on value.  
  %o     Data item is displayed as an octal integer, without a leading zero.  
  %s     Data item is displayed as string.  
  %u     Data item is displayed as an unsigned decimal integer.  
  %x     Data item is displayed as a hexadecimal integer, without a leading 0x.  

The following program illustrates the use of puts function.

printf

gets Home putchar

c program stats