Printf Example Program in C
On this page (7sections)
About this program
This is an example program in simple example programs. Read the concept first: Hello World - Simple C Program, then study the code and output below.
Definition:
In C,the printf function writes a formatted string.
Format Specifiers
- %c char single character
- %d (%i) int signed integer
- %e (%E) float or double exponential format
- %f float or double signed decimal
- %g (%G) float or double use %f or %e as required
- %o int unsigned octal value
- %p pointer address stored in pointer
- %s array of char sequence of characters
- %u int unsigned decimal
- %x (%X) int unsigned hex value
Syntax:
printf("Text to be displayed : %format_specifiers", variable);
Simple Example For Print a Number
/* Example program to print a number In C Programming Language*/
// Header Files
#include<stdio.h>
#include<conio.h>
//Main Function
int main()
{
// Assigining the variable num
int num=100;
// Printing the output
printf("Printing a number:%d",num);
// Output screen waits until get a character
getch();
// Returning to the main function
return 0;
}
Sample Output:
Printing a number:100
Related Pages
Learn the concept first, then study the code:
- C Programs — Browse all C Programs.
- Hello World - Simple C Program — Tutorial — your first C program explained line by line.
- Hello World C Language Example Program — More in simple example programs.
- If Statement Example Program In C Programming Language — More in simple example programs.