Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt

Use this file to discover all available pages before exploring further.

The && (logical AND) operator is a binary operator that performs a boolean conjunction on two scalar operands. It evaluates to 1 (of type int) if both operands compare unequal to zero, and 0 otherwise.
expression1 && expression2

Operand Requirements and Return Type

  • Operands: Both operands must be of scalar types. This includes arithmetic types (integers, floating-point numbers) and pointers. The operands do not need to be of the same type.
  • Return Type: The result is always of type int, strictly yielding either 1 (true) or 0 (false).

Evaluation Mechanics and Short-Circuiting

The && operator enforces strict left-to-right evaluation and utilizes short-circuit evaluation.
  1. expression1 is evaluated first.
  2. If expression1 evaluates to 0 (false), the overall result is immediately determined to be 0. expression2 is not evaluated, meaning any side effects (like function calls, increments, or assignments) within expression2 will not occur.
  3. If expression1 evaluates to a non-zero value (true), expression2 is evaluated. The final result depends entirely on whether expression2 evaluates to a non-zero value.
// Syntax visualization of short-circuit behavior
(0) && (side_effect()) // side_effect() is never executed
(1) && (side_effect()) // side_effect() is executed

Sequence Points

There is a guaranteed sequence point immediately after the evaluation of expression1. This means all side effects of the left operand are fully realized and committed to memory before the right operand is evaluated.
// Sequence point visualization
(x++ > 5) && (x < 10) 
// The increment of x is guaranteed to be complete before x is compared to 10.

Precedence and Associativity

  • Precedence: The && operator has lower precedence than relational operators (like <, >), equality operators (==, !=), and bitwise operators (&, ^, |). It has higher precedence than the logical OR operator (||) and assignment operators (=, +=).
  • Associativity: It groups left-to-right. An expression like a && b && c is parsed as (a && b) && c.
// Precedence visualization
a == b && c & d
// Parsed as: (a == b) && (c & d)
Master C with Deep Grasping Methodology!Learn More