C - Number Type Displaying with printf()

Introduction

The printf() function is ideal for displaying number values.

To display number values, you use conversion characters in the function's formatting string.

The following code displays an integer and a float Values

Demo

#include <stdio.h> 

int main() /* ww  w .j  a  v a  2 s .  c  om*/
{ 
   printf("The value %d is an integer.\n",986); 
   printf("The value %f is a float.\n",98.6); 
   return(0); 
}

Result

The text included in a printf() function is a formatting string. For example

"The value %d is an integer.\n"
"The value %f is a float.\n"

The printf() function's formatting string can contain plain text, escape sequences, and conversion characters, such as the %d and the %f.

These conversion characters act as placeholders for values and variables that follow the formatting string.

For the %d placeholder, the integer value 986 is substituted.

The %d conversion character represents integer values.

For the %f placeholder, the float value 98.6 is substituted.

The %f conversion character represents floating-point values.

The %d and %f are only two of many placeholders for the printf() function's formatting string.

Related Topic