Article View: news.software.readers
Article #262096The EvaluationOrder/Precedence of C/C++ Operators.
From: Jeff-Relf.Me
Date: Wed, 31 May 2017 19:30
Date: Wed, 31 May 2017 19:30
43 lines
2972 bytes
2972 bytes
<PRE Style='Font-Family: OCR A, monospace !important;'>
The Evaluation Order of these expressions are UnDefined/SemiRandom:
i = ++i + i++ ; i = i++ + 1 ; Array[ i ] = i++ ;
Func( ++i, ++i ); Func( i = -1, i = -1 ); Func( i, i++ );
http://en.cppreference.com/w/c/language/eval_order
The middle part of a Conditional Expression ( between ? and : )
is parsed as if parenthesized; for example:
int rv, zz ;
zz = 1, rv = zz ? zz = 1, 2 : zz = 3, 6 ;
printf( L"%d and %d", rv, zz ); // Prints: " 2 and 1 ".
zz = 0, rv = zz ? zz = 1, 2 : zz = 3, 6 ;
printf( L"%d and %d", rv, zz ); // Prints: " 3 and 3 ".
http://en.cppreference.com/w/c/language/operator_precedence
Precedence of C Operators:
Associativity
( Left to right ) Category Operator
----------------- --------------- ----------------------------------------------
Postfix Unary Func() [] -> . ++ --
Right to left Prefix Unary + - ! ~ ++ -- (type) * & sizeof
Multiplicative * / %
Additive + -
Shift << >>
Relational < <= > >=
Equality == !=
Bitwise AND &
Bitwise XOR ^
Bitwise OR |
Logical AND &&
Logical OR ||
N/A Conditional Bool ? True : False
Right to left Assignment = += -= *= /= %= >>= <<= &= ^= |=
Comma ,
http://en.cppreference.com/w/c/language/operator_precedence
Technical Details
Message-ID:
<Jeff-Relf.Me@May.31--0.30pm.Seattle.2017>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!mbox2nntp-comp.lang.c++.(381507).mbox.7z!not-for-mailShow Full Headers
Complete Article Headers
Message-ID: <Jeff-Relf.Me@May.31--0.30pm.Seattle.2017> Subject: The EvaluationOrder/Precedence of C/C++ Operators. Date: Wed, 31 May 2017 19:30:05 +0000 From: Jeff-Relf.Me @. Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!mbox2nntp-comp.lang.c++.(381507).mbox.7z!not-for-mail Newsgroups: comp.os.linux.advocacy,comp.lang.c++,news.software.readers,sci.physics Organization: Glorb Internet Services, http://www.glorb.com Lines: 43 NNTP-Posting-Host: /zlDkqjrFG1Uj/denlv3LA.88.posting.glorb.com Content-Type: Text/HTML; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Complaints-To: abuse@glorb.com NNTP-Posting-Date: Wed, 31 May 2017 19:30:05 +0000 (UTC) User-Agent: Jeff-Relf.Me/X.HTM X-Notice: Scanned by Mr. Bill X-Received-Body-CRC: 3133507198 X-Received-Bytes: 2825