C - printf




 printf

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 Syntax

printf-function
printf("string");
 c-fscanf

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
  1. In this example, “int x” specifies the integer value of the variable x.
  2. Here, “float x” is specifying the float value of the variable y.
  3. Here printf("Enter any two numbers: ") specifies the printf() function being used to print any two numbers in the output screen.
  4. 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
  1. Here in this output “Enter any two numbers: “ is represented in printf statement.
printf-sample-output2
  1. Here in this output we are entering the values 5 and 10.
printf-sample-output3
  1. Here in this output the entered values 5 and 10 are processed in the console window.
  2. Here 5 is represented as integer value and 10.000000 as float value.

View More Quick Examples


Related Searches to c printf function

Adblocker detected! Please consider reading this notice.

We've detected that you are using AdBlock Plus or some other adblocking software which is preventing the page from fully loading.

We don't have any banner, Flash, animation, obnoxious sound, or popup ad. We do not implement these annoying types of ads!

We need money to operate the site, and almost all of it comes from our online advertising.

Please add wikitechy.com to your ad blocking whitelist or disable your adblocking software.

×