What is the return value from printf() function?
What is the return value from printf() function?
- Printf Statement is used to Print Something on Console (On Screen).
- Printf is Predefined function is C Programming Language.
- Printf Statement always returns Integer Value.
Live Example : Return Value of Printf
#include<stdio.h> void main() { int a=20; printf("%d",printf("%d%d%d", a,a,a)); }
Output :
20 20 208
Why we get such Output ?
- Rules : Always Innermost Printf will be executed First .
- Printf function returns the number of characters printed.
- In the Above Example of Nested Printf , Inner Printf Prints [20 20 20] , here number of Characters Printed On Screen = 8 (including two Blank Spaces)
printf("%d",8);
- Outer Printf will Print “8″
Yet Another Sample Example :
#include<stdio.h> void main() { printf("%d",printf("Hello")); }
Output :
Hello5