Exforsys

Online Training

Which has higher priority- Somebody throw highlight on this?

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=++...


Go Back   Exforsys > Programming Talk > C and C++

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 06-17-2006, 06:18 PM
Member
 
Join Date: May 2006
Posts: 45
Allan is on a distinguished road
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-07-2007, 09:12 AM
Senior Member
 
Join Date: Apr 2006
Posts: 139
Ralph is on a distinguished road
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 04:23 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0
Copyright 2004 - 2007 Exforsys Inc. All rights reserved.