Thread: oops output plz...

  1. #1
    Registered User
    Join Date
    Jun 2009
    Posts
    5

    Red face oops output plz...

    main()
    {
    int k=35;
    printf("\n%d%d%d",k==35,k=50,k>50);
    }
    output
    0500 how is tat?..why cant it be 1500


    main()
    {
    int x=15;
    printf("\n%d%d%d",x!=15,x=20,x<30);
    }
    output 1201

    please explain this code and output

    for k==35 it is true o/p should be 1

    for x!=15 it is wrong it should be 0...how?..plz

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    >> 0500 how is tat?..why cant it be 1500

    The standard doesn't dictate the order that the arguments to a function are evaluated. In your case, the assignment was executed first.

    Also, 'main' returns an int, and you need to place you code within code tags and indent it so that it's more readable.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  3. #3
    Registered User
    Join Date
    Jun 2009
    Posts
    5

    thank you

    hi sir,

    I will change my code editing..here k==35 ,it is true but the output is 0..the same in next code

  4. #4
    Registered User
    Join Date
    Jun 2009
    Posts
    5
    we know x=15,but it is x!=15 then it is false ans should be 0

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Post your current code and your current output. Post the well indented code in [code][/code] bbcode tags.
    Last edited by laserlight; 07-01-2009 at 06:02 AM.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    >> here k==35 ,it is true but the output is 0

    Let me give you an example:

    Code:
    #include <stdlib.h>
    #include <stdio.h>
    
    void foo( int, int, int )
    {	}
    
    int bar( const char* text )
    {
    	puts( text );
    	return 0;
    }
    
    int main( void )
    {
    	foo( bar( "one" ), bar( "two" ), bar( "three" ) );
    	return 0;
    }
    You might expect the output to be:

    "one"
    "two"
    "three"

    But in fact, the compiler is free to execute the functions in *any order* that it pleases.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  7. #7
    Registered User
    Join Date
    Jun 2009
    Posts
    5

    Thumbs up thnx

    yaa nice job ...i understood...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. code output...
    By roaan in forum C Programming
    Replies: 6
    Last Post: 07-03-2009, 02:22 AM
  2. Help for my output array
    By qwertysingh in forum C Programming
    Replies: 1
    Last Post: 02-17-2009, 03:08 PM
  3. execl()/fork() output
    By tadams in forum C Programming
    Replies: 19
    Last Post: 02-04-2009, 03:29 PM
  4. Formatting output into even columns?
    By Uncle Rico in forum C Programming
    Replies: 2
    Last Post: 08-16-2005, 05:10 PM
  5. Output problems with structures
    By Gkitty in forum C Programming
    Replies: 1
    Last Post: 12-16-2002, 05:27 AM