Use of Printf In C
Definition:
We use printf in our programs to display information on the screen. The stuff that you write
inside the double quotes will appear on the screen, with some exceptions: a %d will be replaced
by an integer, a %c will be replaced by a character, a %f will be replaced by a float. Here are some
more examples of printf statements, and the output they will produce:.
One last note about printf::
Make sure you use the right format specifier or placeholder [%d
for int, %c for char, %f for float] in your printf statements! Weird things will happen if you
don't.
Example:
Syntax:
Example#2:
Example#3:
We use printf in our programs to display information on the screen. The stuff that you write
inside the double quotes will appear on the screen, with some exceptions: a %d will be replaced
by an integer, a %c will be replaced by a character, a %f will be replaced by a float. Here are some
more examples of printf statements, and the output they will produce:.
One last note about printf::
Make sure you use the right format specifier or placeholder [%d
for int, %c for char, %f for float] in your printf statements! Weird things will happen if you
don't.
Example:
#includeint main() { printf(“int %d float %f char %c” ,10, 25.5, ’*’); printf(“Student percentage is %f and grade is %c”, 90.5, ’A’); printf(“Student percentage is %.2f and grade is %c”, 70.5, ’C’); return 0; } /* notice the output */ //
Syntax:
printf("Hello World");Example#1:
#include/* Includes library file “stdio.h” */ int main() /* Our main function, the starting point of our program! */ { printf("Hello, World!!!"); /* displays Hello, World!!! “ */ return 0; } //
Example#2:
#includeint main() { printf(“Hello, World!!!”); printf(“Hello, World!!!”); } /* notice the output */ //
Example#3:
#includeint main () { printf("Hello \n"); printf("Hello\b \n"); printf("Hello\b\b \n"); printf("Hello\b\b\b \n"); printf("Hello\b\b\b\b \n"); return 0; } /* notice the output */ //