Tuesday, 18 October 2016

Printf : Output Function

Getting Knowledge about input output is the most basic process to start learning any programming language. In C all available function reside in library file whose extension is .h

Stdio.h is header file which has most of the input output related function.I am going to show you most frequently useful function.


Printf function is use to print a string and variable value on monitor.  Various formatting special character used to make formatted output.


Printf(“Formatted string format”,[Variable_List])

Escape sequences
Special function
New Line
Horizontal Tab
Carriage return
Alert Beep
Form feed
Vertical Tab
Single quote
Double quote
Question mark


Printing string

Printf(“Hello Girfa”);

Printing variable

void main()
int a,b,c;


As you can see %d and some variable names are in printf function  calling. What is the mean of these character and format let see following bullet for explanation.

  • Printf function can print string constant with variable data
  • For printing variable . you need to use special character for particular variable.
  • %d is special symbol use to read and write in integer
  • Sequence position of %d decides which variable come first to print.
  • After closing double variable list are seprated by qomma will printf left to right order means value of a will copy on first %d in string then b to second %d and so on.

Formatted Output

Printf function allow you to produce formatted output by making customization using


int n=12345;
printf("\n5 space tab %5d ",n);
printf("\n10 space tab %10d ",n);
printf("\n15 space tab %15d ",n);

Tab Setting C Language

To left justify, use a negative number in the field width

printf("\n10 space tab %-10d ",n);

Floating point printing

  • Use the %f modifer to print floating point values in fixed notation
  • Use %e for exponential notation (Note that the e+02 means "times 10 to the 2nd power" )
  • You can also control the decimal precision, which is the number of places after the decimal. Output will round to the appropriate number of decimal places, if necessary
  • Field width can also be controlled, as with integers
float n=123.45;
printf("\n\tFix Point Decimal Print %f",n);
printf("\n\tTwo digit from point %.2f",n);
printf("\n\tNormal Decimal Print %3e",n);

Float Printing C Language

Character Printing

 char n='a';
printf("\n\tDefault Tab %c",n);
printf("\n\t5 Space Tab %5c",n);
printf("\n\t10 Space Tab %10c",n);

Character Printing C Language

String Printing


String Print C Language

Download pdf