C++ printf() Function Last Updated : 26 Nov, 2022 Comments Improve Suggest changes Like Article Like Report printf() function is originally declared under the <cstdio>header file. It prints the formatted string to the standard output stdout. Syntax: int printf(const char*word, .......) Parameters: word: represents the string that needs to be printed on the standard output stdout,....... : represents any no of extra parameters that can be passed to it. Return Type: It returns the total number of characters written. Example: C++ // C++ Program to demonstrate // use of printf() #include <iostream> using namespace std; int main() { char a[] = "geeksforgeeks"; printf("The total no of characters returned by " "printf() is %d", printf("%s", a)); return 0; } OutputgeeksforgeeksThe total no of characters returned by printf() is 13 To know more about the return type of print() refer to return type of print() and scanf(). Example: C++ // C++ Program to implement // use of % with printf() #include <iostream> using namespace std; int main() { int a = 5; printf("%d", a); } Output5 Note: Anything present with the '%' symbol inside printf() is termed a Format Specifiers. Components of a Format Specifier: A '%' signwidth - It is an optional field that determines the width fieldPrecisionLengthSpecifierFlagsFlags: It is responsible for conversion behavior between two fields. It can be classified into: - : Left Justifies the answer.+ : attached as a sign to the beginning of the result.space : By default, if nothing is present space is attached to the result.# : alternative form of conversion0 : used to pad numbers mostly trailing zeroes in integer or floating-point numbers.Format Specifiers: Format Specifiers are used for taking inputs and printing the output of a type. SpecifierOutputExampled or iSigned decimal integer360uUnsigned decimal integer7200oUnsigned octal555xUnsigned hexadecimal integer7fbeMantissa/Exponent notation4.567e+8cCharacterksstring of charactersgeeks%Prints the % sign to the output screen Note: .x f denotes the precision of float variables up to x decimal places Example 1: C++ // C++ Program to #include <bits/stdc++.h> using namespace std; int main() { char course[]="geeksforgeeks"; printf("Owner of this article is %s",course); return 0; } OutputOwner of this article is geeksforgeeks Example 2: C++ // C++ Program to demonstrate // Use of %._f #include <bits/stdc++.h> using namespace std; int main() { float Self_paced_price = 3999.0, system_design_price = 10999.0; printf("the value of system design price / self paced " "price is %.3f", system_design_price / Self_paced_price); return 0; } Outputthe value of system design price / self paced price is 2.750 .3f depicts the value that should be printed within 3 decimal places. Example 3: C++ // C++ Program implement // Decimal to Octal // Conversion using '%o'. #include <bits/stdc++.h> using namespace std; int main() { int decimal_number = 13; printf("Decimal to Octal conversion of %d is %o", decimal_number, decimal_number); return 0; } OutputDecimal to Octal conversion of 13 is 15 Example 4: C++ // C++ Program to implement // Decimal to hexadecimal // Conversion using '%x' #include <bits/stdc++.h> using namespace std; int main() { int decimal_number = 13; printf("Decimal to Hexadecimal conversion of %d is %x", decimal_number, decimal_number); return 0; } OutputDecimal to Hexadecimal conversion of 13 is d Example 5: C++ // C++ Program to // Char to int Conversion // and Vice Versa. #include <bits/stdc++.h> using namespace std; int main() { int a = 78; printf("%c\n", a); int b = 'g'; printf("%d", b); return 0; } OutputN 103 Comment More infoAdvertise with us Next Article C++ printf() Function R raj2002 Follow Improve Article Tags : Technical Scripter C++ Technical Scripter 2022 Practice Tags : CPP Similar Reads vwprintf() function in C/C++ The vwprintf() function in C++ is used to write a formatted wide string to stdout. It prints formatted data from variable argument list to stdout. Internally, the function retrieves arguments from the list identified by arg as if va_arg was used on it, and thus the state of arg is likely altered by 3 min read vswprintf() function in C/C++ This vswprintf() function writes the wide string to the wide string buffer. A maximum of (len-1) wide characters are written to buffer which is followed by a null wide character. Syntax: int vswprintf( wchar_t* ws, size_t len, const wchar_t* format, va_list arg ) Parameters: The function accepts fou 3 min read C String Functions C language provides various built-in functions that can be used for various operations and manipulations on strings. These string functions make it easier to perform tasks such as string copy, concatenation, comparison, length, etc. The <string.h> header file contains these string functions.Th 6 min read snprintf() in C In C, snprintf() function is a standard library function that is used to print the specified string till a specified length in the specified format. It is defined in the <stdio.h> header file.In this article, we will learn about snprintf() function in C and how to use it in our program.SyntaxC 3 min read isprint() in C The C isprint() function is used to check if a character passed as the argument is a printable character or not. isprint() is defined in the <ctype.h> standard library header file.Printable characters in C are:digits ( 0123456789 )uppercase letters ( ABCDEFGHIJKLMNOPQRSTUVWXYZ )lowercase lette 2 min read C++ <cstdio> The <cstdio> header file is a part of the C++ standard library collection that provides the input and output methods of <stdio.h> library of C language. We can use the traditional C-style input and output method in C++ using the <cstdio> library. It also contains all the functions 7 min read Execution of printf With ++ Operators in C Consider the following statement in C and predict its output.printf("%d %d %d", i, ++i, i++);This statement invokes undefined behavior by referencing both âiâ and âi++â in the argument list.In C, the evaluation order of function arguments is not specified. It means the compiler is free to evaluate a 2 min read modf() in C/C++ In C++, modf() is a predefined function used for mathematical calculations. math.h is the header file required for various mathematical functions. All the functions available in this library take double as an argument and return double as the result. modf() function breaks the given argument into tw 3 min read C++23 <print> Header C++ has long been a powerful language, known for its versatility and performance. With each new standard release, the language evolves, introducing features that enhance developer productivity and code readability. One of these additions of the C++ 23 standard is the introduction of <print> he 3 min read Difference between Printk() and Printf() in Linux While working on a Linux machine, and analyzing some code you might have come across a convention of seeing printk() and printf() written somewhere, and now you wonder.What is the Difference Between Printk() and Printf() in Linux?Well, the answer lies here in this article, lets dive deep and underst 3 min read Like