> ## 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.

# Go Address Of

The `&` operator in Go functions as either a unary address-of operator or a binary bitwise AND operator, depending on the lexical context and the number of operands.

## Unary Operator: Address-Of

When used as a unary operator preceding a single operand, `&` generates a pointer to that operand. If the operand `x` is of a defined type (e.g., `int`), the expression `&x` yields a pointer value of type `*int` containing the memory address of `x`.

```go theme={"dark"}
func addressOfExample() {
    var x int
    p := &x  // p is of type *int
    _ = p    // Blank identifier used to satisfy the compiler
}
```

**Addressability Requirements:**
The operand must be *addressable*. According to the Go specification, addressable operands include:

* Variables
* Pointer indirections (`*p`)
* Slice indexing operations (`s[i]`)
* Field selectors of addressable structs (`obj.field`)
* Array indexing operations of addressable arrays (`arr[i]`)

The `&` operator cannot be applied to unaddressable values, such as:

* Constants
* Basic literal values (e.g., `&42` or `&"string"`)
* Map elements (`m[key]`)
* Return values of function or method calls

**Composite Literals:**
As a syntactic exception, the `&` operator can be applied directly to a composite literal. This operation evaluates the literal, allocates memory for it on the heap or stack, and returns a pointer to the newly allocated value. It is semantically equivalent to using the built-in `new` function followed by initialization.

```go theme={"dark"}
type Config struct { 
    F int 
}

func compositeLiteralExample() {
    // Allocates a Config and returns *Config
    p := &Config{F: 1} 
    _ = p
}
```

## Binary Operator: Bitwise AND

When used as a binary operator between two operands, `&` performs a bitwise AND operation. It evaluates the binary representations of both operands and returns a new value where each bit is `1` only if the corresponding bits in both operands are `1`.

```go theme={"dark"}
func bitwiseAndExample() {
    var a int = 12
    var b int = 10
    c := a & b
    _ = c
}
```

**Type Constraints:**

* Both operands must be of the same integer type (e.g., `int`, `uint8`, `int64`), or both must be untyped constants that can be implicitly converted to a common integer type.
* If one operand is a typed integer and the other is an untyped constant, the untyped constant is implicitly converted to the type of the typed operand (e.g., `var a int8 = 5; c := a & 1` is valid and yields an `int8`).
* The `&` operator cannot be applied to floating-point numbers, complex numbers, or non-numeric types.
* The resulting value shares the same integer type as the operands.

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor Go Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
