Article View: comp.lang.c++
Article #746Re: does an expression in a logical statement need parenthesis for proper evaluation?
From: Janis Papanagnou
Date: Fri, 06 Nov 2026 00:40
Date: Fri, 06 Nov 2026 00:40
37 lines
2263 bytes
2263 bytes
On 2026-11-06 00:42, Lynn McGuire wrote:
> Hi,
>
> Does an expression in a logical statement need parenthesis for proper
> evaluation in C and/or C++?
No, below (assuming i1 and j1 are arithmetic types (and not used
as "camouflaged" booleans) there's no parenthesis necessary.
The necessity of parentheses depends on the operators used. In
"C" the multiplication has higher precedence than the comparison.
I suggest to get an Operator Precedence Table from the Net and
inspect it until you got familiar with the operator precedences.
Most precedences are anyway sensibly defined as you'd expect it.
But be careful when using bit-expressions with '&', '|', and '^'
especially if used together with the comparison operators.
Janis
>
> In other words, should
>
> if (j1 * i1 < 1) {
> goto L463;
> }
>
> be
>
> if ((j1 * i1) < 1) {
> goto L463;
> }
>
> Thanks,
> Lynn
>
Technical Details
Message-ID:
<11cj7mg$23539$2@dont-email.me>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mailReferences:
<11cj4a0$23796$1@dont-email.me>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail From: Janis Papanagnou <janis_papanagnou+ng@hotmail.com> Newsgroups: comp.lang.c++,comp.lang.c Subject: Re: does an expression in a logical statement need parenthesis for proper evaluation? Date: Fri, 6 Nov 2026 01:40:48 +0100 Organization: A noiseless patient Spider Lines: 37 Message-ID: <11cj7mg$23539$2@dont-email.me> References: <11cj4a0$23796$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Fri, 06 Nov 2026 00:40:48 +0000 (UTC) Injection-Info: dont-email.me; logging-data="2200681"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19aNtV+JqvODQnyzEmS+SjP"; posting-host="a1c3eccefbcc1d6f648cf481fadc4299" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:m6e/soH5I1JSkjEShvXMOIonvyY= sha256:OxZx472f9Fjuxp+Rj0bQdheY08eteurI9TnLLcSJPsU= sha1:TnFEa3GwEgsVu7AQrVKJlkWj+v4= sha256:iLTZF8dCNbzK20NWQGoyC+ELtBSy5hXD/6A/EkiLlV8= In-Reply-To: <11cj4a0$23796$1@dont-email.me> Content-Language: en-US