Results 1 to 3 of 3

Thread: printf print values wrong??

  1. #1

    Thread Starter
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    printf print values wrong??

    Take the following printf code:

    Code:
    printf("%f %f %d",x(),y(),z());
    Why would printf print the y() value first and the x() value second I listed them in the correct order? Is this a bug in gcc?

  2. #2
    Hyperactive Member wiccaan's Avatar
    Join Date
    Apr 2004
    Location
    127.0.0.1
    Posts
    475

    Re: printf print values wrong??

    Making a test using printf, I didn't see this issue at all. Using the same thing as you, my code:

    Code:
    #include <iostream>
    #include <conio.h>
    
    float x();
    float y();
    int z();
    
    float x() { return 12.00; }
    float y() { return 34.00; }
    int z() { return 1234; }
    
    int main()
    {
    	printf( "%f %f %d", x(), y(), z() );
    	_getch();
    }
    My output was correct though.

    12.000000 34.000000 1234
    The only thing I could see causing it to not return correctly is that you are mixing up the functions somewhere in the code. As in x is being given the value of y, and y being given the value of x somewhere. Double check that the code is correct and each function is being given the correct value in the end result before attempting to print it out.
    If my post was helpful please rate it

  3. #3

    Thread Starter
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    Re: printf print values wrong??

    Thanks. That is exactly what I thought. This question was posed at another forum and didn't make sense for printf to give wrong output like that. There are logical errors why, but don't think it's a bug.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width