oops output plz...

This is a discussion on oops output plz... within the C Programming forums, part of the General Programming Boards category; 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); ...

  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,699
    >> 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:
    bool fun(bool value)
    {
        return std::pow(std::exp(1), std::complex<float>(0, 1) 
        * std::complex<float>(std::atan(1)*(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
    21,606
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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,699
    >> 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:
    bool fun(bool value)
    {
        return std::pow(std::exp(1), std::complex<float>(0, 1) 
        * std::complex<float>(std::atan(1)*(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, 02:08 PM
  3. execl()/fork() output
    By tadams in forum C Programming
    Replies: 19
    Last Post: 02-04-2009, 02: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, 04:27 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21