Home » C programs » stdio.h header file functions

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

printf() function in C

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

Prototype:

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

Parameters: const char* str, more optional parameters

Return type: int

Use of function:

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.

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






Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.