What Value Is Returned By Printf And Scanf In C

Prashant | Sun, 14 Jun, 2020 | 147

Returned values of printf and scanf in C language

In this tutorial we are gonna learn that what value is returned by printf and scanf funcrtions ?

1) Return type and value of printf function

printf is a library function of stdio.h, it is used to display messages as well as values on the standard output device (monitor).

printf returns an integer value, which is the total number of printed characters.

For example: if you are printing "Hello" using printf, printf will return 5.

Consider the program:

#include <stdio.h>

int main()
{
	int result;
	result = printf("Hello\n");
	printf("Total printed characters are: %d\n",result);
	
	return 0;
}

Output

Hello
Total printed characters are: 6

In first statement "Hello\n" there are 6 characters, "\n" is a single character to print new line, it is called new line character. Thus, total number of printed characters are: 6.

2) Return type and value of scanf

scanf is a library function of stdio.h, it is used to take input from the standard input device (keyboard).

scanf returns an integer value, which is the total number of inputs.

For example: if you are reading two values from scanf, it will return 2.

Consider the program:

#include <stdio.h>

int main()
{
	int a,b;
	int result;
	
	printf("Enter two number: ");
	result=scanf("%d%d",&a,&b);
	printf("Total inputs are: %d\n",result);
	
	return 0;
}

Output

Enter two number: 10 20
Total inputs are: 2.

 

 

 

 

 

 

Related Articles :- 

1Introduction And Getting Started With C

2Basic Of C Language

3. Why We Should Use C Language

4. Applications Of C Programming

5. Basic Rules For Writting C Program

6. Keywords In C Language

7. Comments In C Programming

8. Tokens In C

9. Difference Between Int Main And Void Main

10. C Processor And Macros

11. Variables In C

12. Types Of Variables In C

13. Difference Between Local And Global Variable

14. Difference Bwtween Auto / Extern / Static Variable

15. Constant In C

16. How To Access Global Variable Using Extern Keyword In C

17. Exit And Return Staterment In C

18. Print Float Value Upto N Decimals In C Programming

19. How To Print Multiline Message Using Single Printf In C Programming ?

20. What Value Returned By Scanf Function In C Language ?

21. What Value Is Returned By Printf And Scanf In C

22. What Do 'Lvalue' And 'Rvalue' Mean In C/C++?

23. Errors In C Programming ?

0 comments
Leave a comment