C - printf
![printf](https://wikitechy.com/cdn/tutorials/c-programming/printf.gif)
Learn C - C tutorial - printf - C examples - C programs
C - printf() Function - Definition and Usage
- The printf function is not the part of the C language, because there is no input or output defined in C language itself.
- In C , printf() function is used to print the “character, string, float, integer, octal and hexadecimal values” onto the output screen.
- We use printf() function with %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 and %x for hexadecimal variable.
- To generate a newline,we use “\n” in C printf() statement.
![C printf Function C printf Function](https://wikitechy.com/cdn/tutorials/c-programming/c-printf-function.png)
C Syntax
![printf-function printf-function](https://wikitechy.com/cdn/tutorials/c-programming/printf.png)
printf("string");
![c-fscanf](https://wikitechy.com/cdn/tutorials/c-programming/c-printf.gif)
Sample coding - C - printf Function
#include<stdio.h>
#include<conio.h>
void main()
{
int x;
float y;
clrscr();
printf("Enter any two numbers: ");
scanf("%d %f",&x,&y);
printf("%d %f",x,y);
getch();
}
C Code - Explanation
![code-explanation-printf-function code-explanation-printf-function](https://wikitechy.com/cdn/tutorials/c-programming/code-explanation-printf-function.png)
- In this example, “int x” specifies the integer value of the variable x.
- Here, “float x” is specifying the float value of the variable y.
- Here printf("Enter any two numbers: ") specifies the printf() function being used to print any two numbers in the output screen.
- In this example, printf("%d %f",x,y) specifies that %d is an format specifier of integer value for the variable x. And %f is a float value of the variable y.
Sample Output - Programming Examples
![printf-sample-output1 printf-sample-output1](https://wikitechy.com/cdn/tutorials/c-programming/printf-sample-output1.png)
- Here in this output “Enter any two numbers: “ is represented in printf statement.
![printf-sample-output2 printf-sample-output2](https://wikitechy.com/cdn/tutorials/c-programming/printf-sample-output2.png)
- Here in this output we are entering the values 5 and 10.
![printf-sample-output3 printf-sample-output3](https://wikitechy.com/cdn/tutorials/c-programming/printf-sample-output3.png)
- Here in this output the entered values 5 and 10 are processed in the console window.
- Here 5 is represented as integer value and 10.000000 as float value.