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 = operator in C is the simple assignment operator. It evaluates the expression on its right side (the rvalue) and stores the resulting value into the memory location designated by the operand on its left side (the modifiable lvalue).
lvalue = rvalue;
Operand Requirements
  • Left Operand: Must be a modifiable lvalue. This is an expression that designates an accessible memory location (e.g., a scalar variable, a dereferenced pointer, or a struct member) that is not qualified with const and is not an array type.
  • Right Operand: Must be an expression that evaluates to a value (an rvalue) whose type is assignment-compatible with the left operand.
Evaluation and Return Value The assignment operation is itself an expression. It evaluates to the value that was successfully stored in the left operand. The type of the resulting expression is the unqualified type of the left operand. Because the operator yields a value, assignments can be chained.
a = b = c = expression; 
Associativity and Precedence
  • Associativity: Right-to-left. In a chained assignment, the rightmost assignment is evaluated and executed first. The code block above is parsed as a = (b = (c = expression)).
  • Precedence: The = operator has very low precedence (level 14 out of 15). It ranks below all arithmetic, relational, bitwise, and logical operators, but strictly above the comma (,) operator.
Type Conversion If the type of the right operand differs from the type of the left operand, the C compiler performs an implicit type conversion. The value of the right operand is converted to the type of the left operand before the assignment occurs. This can result in truncation, sign extension, or loss of precision depending on the standard integer promotion and floating-point conversion rules.
int_lvalue = float_rvalue; /* float is implicitly truncated to int */
Sequence Points and Undefined Behavior The = operator does not introduce a sequence point. The C standard leaves the evaluation order of the left and right operands unspecified. If the evaluation of the right operand modifies the memory location designated by the left operand, or if the same memory location is modified more than once within the expression without an intervening sequence point, the program exhibits undefined behavior.
/* Undefined behavior: no sequence point between the evaluations of 'i' */
i = ++i; 
Master C with Deep Grasping Methodology!Learn More