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 & symbol in C represents two distinct operators depending on its lexical context and arity: the unary address-of operator, which yields the memory address of its operand, and the binary bitwise AND operator, which performs a bit-by-bit logical conjunction on two integer operands.

Unary & (Address-of Operator)

When used as a prefix unary operator, & evaluates to the memory address of its operand, effectively generating a pointer value that points to that object within the C abstract machine.
&operand
Technical Mechanics:
  • Operand Constraints: The operand must be a valid lvalue (an expression that designates an object with an identifiable memory location), a function designator, or an array name.
  • Restrictions: The unary & cannot be applied to expressions that are not lvalues (such as literal constants or temporary expression results), bit-fields within a struct, or variables explicitly declared with the register storage class specifier.
  • Type Evaluation: If the operand is of type T, the resulting expression &operand evaluates to a value (which is not an lvalue) of type T* (pointer to T).
Code Example:
#include <stdio.h>

int main(void) {
    int val = 42;
    
    /* Unary & yields the memory address of the lvalue 'val' */
    int *ptr = &val; 
    
    printf("Value: %d, Address: %p\n", val, (void*)ptr);
    return 0;
}

Binary & (Bitwise AND Operator)

When used as an infix binary operator, & performs a bitwise logical AND operation. It compares the binary representations of two operands bit-by-bit, yielding a new value based on strict logical conjunction.
operand1 & operand2
Technical Mechanics:
  • Operand Constraints: Both operands must be of integral types (e.g., char, short, int, long, or their unsigned variants). The operator cannot be applied to floating-point types, pointers, or aggregate types.
  • Type Promotion: Prior to the operation, the compiler applies the usual arithmetic conversions to both operands to establish a common type. The result of the expression evaluates to this common promoted integral type.
  • Evaluation Logic: For each corresponding bit position in the promoted operands, the resulting bit is set to 1 if and only if both operand bits are 1. Otherwise, the resulting bit is 0.
// Bitwise AND Truth Table
Bit A   Bit B   Result (A & B)
  0       0           0
  0       1           0
  1       0           0
  1       1           1
Code Example:
#include <stdio.h>

int main(void) {
    unsigned int flags = 0x0F; /* Binary: 0000 1111 */
    unsigned int mask  = 0x05; /* Binary: 0000 0101 */
    
    /* Binary & performs bit-by-bit logical conjunction */
    unsigned int masked_result = flags & mask; 
    
    /* Result is 0x05 (Binary: 0000 0101) */
    printf("Result: 0x%02X\n", masked_result); 
    return 0;
}
Master C with Deep Grasping Methodology!Learn More