Thread: Give the output of the following program and justify why this output will be obtained

  1. #1
    Registered User
    Join Date
    Apr 2016
    Posts
    2

    Give the output of the following program and justify why this output will be obtained

    Code:
    #define PRINT(int) printf("int=%d\n",int)    #define PRINT1(x,y,z) printf("x=%d\ty=%d\tz=%d\n",x,y,z)    main()    {        int x=1,y=1,z=1;        x+=y+=z;        PRINT(x<y?y:x);        x=y=z=1;        ++x||++y&&++z;        PRINT1(x,y,z);        x=y=z=-1;        ++x&&++y||++z;        PRINT1(x,y,z);    }

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    The forum software may have messed up your code, but in any case, you need to post the code as-is, with proper formatting.

    Then, you should venture an answer to the question instead of expecting people to do your homework for you.
    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

  3. #3
    Registered User
    Join Date
    Sep 2014
    Posts
    364
    After reformating:
    Quote Originally Posted by Md Shadab View Post
    Code:
    #define PRINT(int) printf("int=%d\n",int)
    #define PRINT1(x,y,z) printf("x=%d\ty=%d\tz=%d\n",x,y,z)
    
    
    main()
    {
        int x=1,y=1,z=1;
        x+=y+=z;
        PRINT(x<y?y:x);
        x=y=z=1;
        ++x||++y&&++z;
        PRINT1(x,y,z);
        x=y=z=-1;
        ++x&&++y||++z;
        PRINT1(x,y,z);
    }
    First Question: is your spacebar broken? I can't find any space in your code. This make it hard to read the code. There is no turnament who uses less space, so you can use it.
    Code:
    main()
    should be
    Code:
    int main(void)
    and main should return an integer.
    You should include <stdio.h> for using 'printf()'.

    To your headline: What output do you see and what output you are expect? Can you explain the output?
    Other have classes, we are class

  4. #4
    Registered User
    Join Date
    Apr 2016
    Posts
    2
    Give the output of the following program and justify why this output will be obtained-abc-jpg This the source code + output, I want to know how this output came, my main concern is "++x||++y&&++z;" ...

  5. #5
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    Don't post a screenshot of your code, use code tags. You can preview the code in the advanced editor to ensure it looks correct (be sure to paste as text).

    Did you attempt to understand the code? If not, get a pen and paper, and step through the code "by hand", keeping track of values and the result of expressions.

  6. #6
    Registered User
    Join Date
    Jun 2015
    Posts
    1,640
    Try putting explicit parentheses in the statements according to the operator precedence/associativity rules. You also need to take account of short-circuit evaluation of the logical operators.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ overlapping output and adding extensions to output files
    By lordmorgul in forum Linux Programming
    Replies: 9
    Last Post: 05-11-2010, 08:26 AM
  2. How to edit output in struct and call for the output
    By andrewkho in forum C Programming
    Replies: 4
    Last Post: 03-16-2010, 10:28 PM
  3. terminal output not showing output properly
    By stanlvw in forum C Programming
    Replies: 13
    Last Post: 11-19-2007, 10:46 PM
  4. output a string to a standard output
    By sh4k3 in forum C Programming
    Replies: 3
    Last Post: 06-15-2007, 05:59 AM
  5. Replies: 3
    Last Post: 02-19-2003, 08:34 PM

Tags for this Thread