Results 1 to 15 of 15

Thread: What does printf function returns?

  1. #1
    Junior Member
    Join Date
    Mar 2008
    Answers
    1

    What does printf function returns?

    I mean that it may return whether how many no of variables printed or how many bytes of variables to be printed.


  2. #2
    Junior Member
    Join Date
    Jul 2007
    Answers
    10

    Re: What does printf function returns?

    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.


  3. #3
    Junior Member
    Join Date
    Mar 2008
    Answers
    1

    Re: What does printf function returns?

    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=&#37;d j=%d",i,j);
    printf("%d",z);
    }


  4. #4

    Re: What does printf function returns?

    Hello,

    Printf() will return the number of arguments it prints


  5. #5
    Junior Member
    Join Date
    May 2008
    Answers
    2

    Re: What does printf function returns?

    Hi
    printf will return number of character passed to the fierst string......


  6. #6
    Junior Member
    Join Date
    May 2008
    Answers
    2

    Re: What does printf function returns?

    print f ( ) returns the number of characters are passed within " " (double quoted).


  7. #7

    Re: What does printf function returns?

    I agree with Kailash, it returns the number of characters the function prints on the display device...


  8. #8
    Junior Member
    Join Date
    Jan 2010
    Answers
    1

    Re: What does printf function returns?

    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.


  9. #9
    Expert Member
    Join Date
    May 2008
    Answers
    100

    Thumbs up Re: What does printf function returns?

    Quote Originally Posted by mohantyrk1 View Post
    print f ( ) returns the number of characters are passed within " " (double quoted).
    I Completely agree with what mohantyrk is saying.It returns the no of characters inside " " (Double quote). On error it returns EOF.


  10. #10

    Re: What does printf function returns?

    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.

  11. #11

    Re: What does printf function returns?

    it is a fact that every function should return a value.
    please tell clearly what print and other libarary function return.


  12. #12
    Junior Member
    Join Date
    Dec 2009
    Answers
    2

    Re: What does printf function returns?

    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.


  13. #13

    Re: What does printf function returns?

    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("");


  14. #14
    Junior Member
    Join Date
    Mar 2009
    Answers
    2

    Re: What does printf function returns?

    [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........


  15. #15

    Re: What does printf function returns?

    [QUOTE=sandesh k;52091]
    Quote Originally Posted by sudharshan_3apr View Post
    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........
    The value of x comes from previous printf() the space after \n doesn't matter


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact