printf() function in C language with Example

Here, we are going to learn about the printf() function of library function stdio.h in C language with its syntax, example.
Submitted by Souvik Saha, on February 22, 2019 [Last updated : December 26, 2023]

printf() – Description and Usages

The printf() function is defined in the <stdio.h> header file.

Prototype

int printf(const char* str, . . .);

Parameter(s)

const char* str, more optional parameters

Return Type

int

Use of printf() function in C

The printf() function writes the arguments which are written in the double inverted quotes, on the stdout stream. The prototype of the function printf() is int printf( const char* str, ...);

The string pointed by the str consists of two types of items. The first item is the data types which are printed on the screen and the second is the format of the data type. It returns the total number of characters printed or a negative value if an output error.

pritnf() format specifiers

There are some formats of some data types is c,

code     Format   
%c      Display Character
%d      Display signed integer number
%f      Display floating point number
%ld     Display double numbers 
%s      Display string
%p      Display pointer
%x      Display hexadecimal numbers

printf() example in C

#include <stdio.h>

int main()
{

    printf("Print a character - %c\n", 'a');
    printf("Print a number - %d\n", 10);
    printf("Print a decimal number - %f\n", 5.25);
    printf("Print a string - %s\n", "hello");

    return 0;
}

Output

printf() example in C language

C stdio.h Library Functions Programs »

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.