Return values of printf() and scanf() in C/C++ Last Updated : 29 Nov, 2020 Comments Improve Suggest changes Like Article Like Report What values do the printf() and scanf() functions return ? printf() : It returns total number of Characters Printed, Or negative value if an output error or an encoding error Example 1: The printf() function in the code written below returns 6. As 'CODING' contains 6 characters. CPP // C/C++ program to demonstrate return value // of printf() #include <stdio.h> int main() { char st[] = "CODING"; printf("While printing "); printf(", the value returned by printf() is : %d", printf("%s", st)); return 0; } OutputWhile printing CODING, the value returned by printf() is : 6 Example 2: The printf() function in the code written below returns 9. As '123456789' contains 9 characters. CPP // C/C++ program to demonstrate return value // of printf() #include <stdio.h> int main() { long int n = 123456789; printf("While printing "); printf(", the value returned by printf() is : %d", printf("%ld", n)); return 0; } OutputWhile printing 123456789, the value returned by printf() is : 9 scanf() : It returns total number of Inputs Scanned successfully, or EOF if input failure occurs before the first receiving argument was assigned.Example 1: The first scanf() function in the code written below returns 1, as it is scanning 1 item. Similarly second scanf() returns 2 as it is scanning 2 inputs and third scanf() returns 3 as it is scanning 3 inputs. CPP // C/C++ program to demonstrate return value // of printf() #include <stdio.h> int main() { char a[100], b[100], c[100]; // scanf() with one input printf("\n First scanf() returns : %d", scanf("%s", a)); // scanf() with two inputs printf("\n Second scanf() returns : %d", scanf("%s%s", a, b)); // scanf() with three inputs printf("\n Third scanf() returns : %d", scanf("%s%s%s", a, b, c)); return 0; } Input: Hey! welcome to geeks for geeks Output: First scanf() returns : 1 Second scanf() returns : 2 Third scanf() returns : 3 Comment More infoAdvertise with us Next Article Return values of printf() and scanf() in C/C++ kartik Follow Improve Article Tags : C Language GFacts cpp-input-output C-Input and Output Quiz Similar Reads Cin-Cout vs Scanf-Printf Regular competitive programmers face common challenge when input is large and the task of reading such an input from stdin might prove to be a bottleneck. Such problem is accompanied with âWarning: large I/O dataâ. Let us create a dummy input file containing a line with 16 bytes followed by a newlin 3 min read Use of & in scanf() but not in printf() Why there is need of using '&' in case of scanf function while not in case of printf function. Examples: scanf("%d %d", &a, &b);printf("%d %d", a, b);As a and b above are two variable and each has their own address assigned but instead of a and b, we send the address of a and b respectiv 1 min read Print an Integer Value in C Printing an Integer in C is one of the most basic tasks. Input and output of the elements are essential for taking input from the user and then giving the output to the user. Here we are going to take an integer as input from the user with the help of the scanf() function and print that integer with 2 min read C Function Arguments and Function Return Values Prerequisite: Functions in CA function in C can be called either with arguments or without arguments. These functions may or may not return values to the calling functions. All C functions can be called either with arguments or without arguments in a C program. Also, they may or may not return any v 5 min read What does main() return in C and C++? C According to coding standards, a good return program must exit the main function with 0. Although we are using void main() in C, In which we have not suppose to write any kind of return statement but that doesn't mean that C code doesn't require 0 as exit code. Let's see one example to clear our t 3 min read Difference between return and printf in C In C programming, return and print serve fundamentally different purposes and they are used in distinct contexts to achieve specific tasks. Let's see each of them and see what are their functions and differences. 1. Return Statement In C, return is a statement used within a function to terminate the 2 min read scanf() and fscanf() in C In C language, scanf() function is used to read formatted input from stdin. It returns the whole number of characters written in it otherwise, returns a negative value.Syntax:int scanf(const char *characters_set)Time Complexity: O(n)Auxiliary Space: O(n) where n is the length of input.Many of us kno 4 min read How can I return multiple values from a function? In C programming, a function can return only one value directly. However, C also provides several indirect methods in to return multiple values from a function. In this article, we will learn the different ways to return multiple values from a function in C.The most straightforward method to return 3 min read What is use of %n in printf() ? In C printf(), %n is a special format specifier which instead of printing something causes printf() to load the variable pointed by the corresponding argument with a value equal to the number of characters that have been printed by printf() before the occurrence of %n. C #include<stdio.h> int 1 min read Difference between scanf() and gets() in C scanf()It is used to read the input(character, string, numeric data) from the standard input(keyboard).It is used to read the input until it encounters a whitespace, newline or End Of File(EOF). For example see the following code:Â C // C program to see how scanf() // stops reading input after white 3 min read Like