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); }
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); }
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.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
After reformating:
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.
should beCode:main()
and main should return an integer.Code:int main(void)
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
This the source code + output, I want to know how this output came, my main concern is "++x||++y&&++z;" ...
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.
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.