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

1. ## 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. 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.

3. After reformating:
Originally Posted by Md Shadab
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?

4. This the source code + output, I want to know how this output came, my main concern is "++x||++y&&++z;" ...

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