I mean that it may return whether how many no of variables printed or how many bytes of variables to be printed.
I mean that it may return whether how many no of variables printed or how many bytes of variables to be printed.
printf function is library function and and you can also include own library function in c language using header file.
printf function does not return any value not even void.
printf function return the total number of characters (or can say bytes) to be printed on the screen.It doesn't return number of variables.
As a proof you can compile below progam and run it will return 9
#include<stdio.h>
void main()
{
int i=0,j=100,z;
z=printf("i=%d j=%d",i,j);
printf("%d",z);
}
Hello,
Printf() will return the number of arguments it prints
Hi
printf will return number of character passed to the fierst string......
print f ( ) returns the number of characters are passed within " " (double quoted).
I agree with Kailash, it returns the number of characters the function prints on the display device...
Upon a successful return, the printf() function returns the number of characters printed (not including the trailing '\0' used to end output to strings). If the output was truncated due to this limit then the return value is the number of characters (not including the trailing '\0') which would have been written to the final string if enough space had been available. Thus, a return value of size or more means that the output was truncated. If an output error is encountered, a negative value is returned.
user defined function also returns some value please some one tell me exact ans.
Last edited by anurag vaishwade; 01-17-2010 at 03:40 PM.
it is a fact that every function should return a value.
please tell clearly what print and other libarary function return.
There are following three possibilities regarding values returned by printf() function.
1. printf() returns no. of arguments(variables) passed to it if only variables are passed to it.
Ex :
#include<stdio.h>
void main()
{
int a=1,b=1,c=1,d=1,x=0;
x=printf("%d%d%d%d",a,b,c,d);
printf("\n x=%d",x);
}
In above code value of x will be :
x=4
Because four variables are passed to it.
2. printf() will return no. of characters if only string is passed to it.
Ex:
#include<stdio.h>
void main()
{
int x=0;
x=printf("hello");
printf("%d",x);
}
In above code value of x will be :
x=5
Because the string(hello) passed to contains five characters.
3. If printf() statement contains both strings and variables, then it will return sum of no. of characters in the string(s) and no. of variables.
Ex:
#include<stdio.h>
void main()
{
int x=0,a=1,b=2,c=3,d=4;
x=printf("qwert%d%d%d%d",a,b,c,d);
printf("%d",x);
}
In above code value of x will be :
x=9
Because the string(qwert) contains five characters and a,b,c,d are four variables are passed to it. So 5+4=9.
i disagree with u (sorry i dunno who u r) for certain special cases.
#include<stdio.h>
void main()
{
int a=10,b=1,c=1,d=1,x=0;
x=printf("%d%d%d%d",a,b,c,d);
printf("\n x=%d",x);
}
for the above prog it ll return x=5.
2. printf() will always return no of characters it has successfully outputted to the console screen.
Ex:
#include<stdio.h>
void main()
{
int x=0;
x=printf("hello");
printf("%d",x);
}
the output was clearly explained for above.But if this the case..
printf("hi i'm\0there");
Mr.Faizan's statement becomes false..
and also printf() will return EOFmacro valued -1 for the foll
int x=printf("");
[QUOTE=sudharshan_3apr;52052]i disagree with u (sorry i dunno who u r) for certain special cases.
#include<stdio.h>
void main()
{
int a=10,b=1,c=1,d=1,x=0;
x=printf("%d%d%d%d",a,b,c,d);
printf("\n x=%d",x);
}
for the above prog it ll return x=5.
this is because there is a space after \n in your statement and it is a string ,hence it is 1+4=5........