This is a discussion on Which has higher priority- Somebody throw highlight on this? within the C and C++ forums, part of the Programming Talk category; Hi All, I have a code as below main () { int x,y,z; x=1; y=-1; z=2; z=++...
|
|||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Which has higher priority- Somebody throw highlight on this?
Hi All,
I have a code as below main () { int x,y,z; x=1; y=-1; z=2; z=++x&&++y||++z; printf("x=%d y=%d z=%d",x,y,z); } In the above code I could not figure out which takes higher precedence whether && or ||. Only if I could get this idea clear my output would be correct. So somebody clarify this. Regards, Allan |
|
|||
|
The logical AND denoted as && takes precedence over logical OR denoted as ||.For both the order of operations would be from left to right.
The process of output would be as follows: ++x is equal to 2 ++y is equal to 0 ++z is equal to 3 So ++x&&++y is equal to 2&&0 which is equal to 0 and so 0||++z is equal to 0||3 which is equal to true. Allan I assume your query is clarified. |