473,406 Members | 2,293 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

expression evaluation : help!

hi all ,
the expression in question is

++i&&++j||++k

most sources say that since the result of the || operation is decided
by the LHS itself , the right side is not computed

my point of thinking is that since the unary operator has higher
precedence than || , it will be evaluated before || in any
case...........where am im going wrong

thanks in anticipation

Manan

Nov 14 '05 #1
8 1583
ma************@gmail.com scribbled the following:
hi all ,
the expression in question is ++i&&++j||++k most sources say that since the result of the || operation is decided
by the LHS itself , the right side is not computed my point of thinking is that since the unary operator has higher
precedence than || , it will be evaluated before || in any
case...........where am im going wrong


Where you're going wrong is thinking precedence and order of evaluation
are the same thing. They're nothing of the sort. Precedence dictates how
a string of C tokens is compiled into an expression. Order of evaluation
dictates how that expression is evaluated at run-time.

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-------------------------------------------------------- rules! --------/
"C++. C++ run. Run, ++, run."
- JIPsoft
Nov 14 '05 #2
ma************@gmail.com wrote:
hi all ,
the expression in question is

++i&&++j||++k

most sources say that since the result of the || operation is decided
by the LHS itself , the right side is not computed

my point of thinking is that since the unary operator has higher
precedence than || , it will be evaluated before || in any
case...........where am im going wrong


See FAQ 3.5 and 3.8, best read the whole section 3:
http://www.eskimo.com/~scs/C-faq/s3.html

Note: The ASCII text version posted here by Steve Summit is
more complete/up to date than the above HTML version but can
be obtained following the links from
http://www.eskimo.com/~scs/C-faq/top.html
Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Nov 14 '05 #3
Michael Mair <Mi**********@invalid.invalid> scribbled the following:
ma************@gmail.com wrote:
hi all ,
the expression in question is

++i&&++j||++k

most sources say that since the result of the || operation is decided
by the LHS itself , the right side is not computed

my point of thinking is that since the unary operator has higher
precedence than || , it will be evaluated before || in any
case...........where am im going wrong
See FAQ 3.5 and 3.8, best read the whole section 3:
http://www.eskimo.com/~scs/C-faq/s3.html Note: The ASCII text version posted here by Steve Summit is
more complete/up to date than the above HTML version but can
be obtained following the links from
http://www.eskimo.com/~scs/C-faq/top.html


ITYM also see FAQ 3.4, which answers the OP's question pretty much
directly.

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-------------------------------------------------------- rules! --------/
"I wish someone we knew would die so we could leave them flowers."
- A 6-year-old girl, upon seeing flowers in a cemetery
Nov 14 '05 #4
On 2005-02-22 13:55:49 -0500, ma************@gmail.com said:
hi all ,
the expression in question is

++i&&++j||++k

most sources say that since the result of the || operation is decided
by the LHS itself , the right side is not computed
This is true. If the left-hand side of || is true, then the right-hand
side will never be evaluated. So, in your above expression, if (++i)
evaluates to a non-zero value, and (++j) does as well, then k will
never be incremented.
my point of thinking is that since the unary operator has higher
precedence than || , it will be evaluated before || in any
case...........where am im going wrong


The point that you're missing is that precedence has nothing to do with
order of evaluation.

--
Clark S. Cox, III
cl*******@gmail.com

Nov 14 '05 #5
Joona I Palaste wrote:
Michael Mair <Mi**********@invalid.invalid> scribbled the following:
ma************@gmail.com wrote:
hi all ,
the expression in question is

++i&&++j||++k

most sources say that since the result of the || operation is decided
by the LHS itself , the right side is not computed

my point of thinking is that since the unary operator has higher
precedence than || , it will be evaluated before || in any
case...........where am im going wrong


See FAQ 3.5 and 3.8, best read the whole section 3:
http://www.eskimo.com/~scs/C-faq/s3.html


Note: The ASCII text version posted here by Steve Summit is
more complete/up to date than the above HTML version but can
be obtained following the links from
http://www.eskimo.com/~scs/C-faq/top.html

ITYM also see FAQ 3.4, which answers the OP's question pretty much
directly.


No, I plainly oversaw it when I was quickly scanning for special
questions to point out -- some people are scared by
"read the whole section" ;-)
Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Nov 14 '05 #6
Michael Mair <Mi**********@invalid.invalid> scribbled the following:
Joona I Palaste wrote:
Michael Mair <Mi**********@invalid.invalid> scribbled the following:
ma************@gmail.com wrote:
hi all ,
the expression in question is

++i&&++j||++k

most sources say that since the result of the || operation is decided
by the LHS itself , the right side is not computed

my point of thinking is that since the unary operator has higher
precedence than || , it will be evaluated before || in any
case...........where am im going wrong
See FAQ 3.5 and 3.8, best read the whole section 3:
http://www.eskimo.com/~scs/C-faq/s3.html

Note: The ASCII text version posted here by Steve Summit is
more complete/up to date than the above HTML version but can
be obtained following the links from
http://www.eskimo.com/~scs/C-faq/top.html


ITYM also see FAQ 3.4, which answers the OP's question pretty much
directly.

No, I plainly oversaw it when I was quickly scanning for special
questions to point out -- some people are scared by
"read the whole section" ;-)


Does your reply "no" to my "ITYM" mean "no, that's just plain wrong" or
"no, I didn't think of that"?

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-------------------------------------------------------- rules! --------/
"I am looking for myself. Have you seen me somewhere?"
- Anon
Nov 14 '05 #7
Joona I Palaste wrote:
Michael Mair <Mi**********@invalid.invalid> scribbled the following:
Joona I Palaste wrote:
Michael Mair <Mi**********@invalid.invalid> scribbled the following:

ma************@gmail.com wrote:

>hi all ,
>the expression in question is
>
>++i&&++j||++k
>
>most sources say that since the result of the || operation is decided
>by the LHS itself , the right side is not computed
>
>my point of thinking is that since the unary operator has higher
>precedence than || , it will be evaluated before || in any
>case...........where am im going wrong

See FAQ 3.5 and 3.8, best read the whole section 3:
http://www.eskimo.com/~scs/C-faq/s3.html

Note: The ASCII text version posted here by Steve Summit is
more complete/up to date than the above HTML version but can
be obtained following the links from
http://www.eskimo.com/~scs/C-faq/top.html

ITYM also see FAQ 3.4, which answers the OP's question pretty much
directly.

No, I plainly oversaw it when I was quickly scanning for special
questions to point out -- some people are scared by
"read the whole section" ;-)


Does your reply "no" to my "ITYM" mean "no, that's just plain wrong" or
"no, I didn't think of that"?


The latter :-)
Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Nov 14 '05 #8
thanks a lot everyone ....cheers
manan

Nov 14 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Elaine Jackson | last post by:
If bool(B_i)==True for 1<=i<=n and j is the smallest i with bool(A_j)==True, then the evaluation of (A_1 and B_1) or ... or (A_n and B_n) returns B_j without evaluating any other B_i. This is such...
1
by: Simon Wigzell | last post by:
A client wants have acess to an online databases records controlled by group strings and evaluation strings e.g., each use would have in his client record a group string like this: And each...
4
by: Frank Wallingford | last post by:
Note: For those with instant reactions, this is NOT the common "why is i = i++ not defined?" question. Please read on. I came across an interesting question when talking with my colleagues....
2
by: Jeffrey Ganping Chen | last post by:
I'm trying to build a generic runtime C# expression evaluation engine to allow the user to evaluate any C# code blocks at runtime within the application's context. For example, obj4.p4 =...
8
by: Brian Blais | last post by:
Hello, I have a string input from the user, and want to parse it to a number, and would like to know how to do it. I would like to be able to accept arithmetic operations, like: '5+5'...
9
by: sarathy | last post by:
Hi, Can anyone just help me with what exactly is constant expression. I read the section on Constant expression in K&R2. i am not fully clear with it.
21
by: Steven T. Hatton | last post by:
I'm trying to improve my formal understanding of C++. One significant part of that effort involves clarifying my understanding of the vocabulary used to describe the language. This is from the...
2
by: Tim Johnson | last post by:
I'm having trouble understanding this part of the expression evaluation rules ('6.5 Expressions', second item, C99 spec; the C++ wording is presumably identical): What precisely does the...
32
by: silpau | last post by:
hi, i am a bit confused on expression evaluation order in expressions involving unary increment.decrement operators along with binary operators. For example in the following expression x...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.