• Home
  • JavaScript
    • Introduction to JavaScript
    • JavaScript Developer
  • TypeScript
    • Introduction to TypeScript
    • TypeScript Developer
  • React.js
    • Introduction to React
    • React Developer
  • Python
    • Introduction to Python
    • Python Developer
  • C++
    • Introduction to C++
    • C++ Developer
  • C Language
    • Introduction to C
    • C Developer
  • Rust
    • Introduction to Rust
    • Rust Developer
  • Zig
    • Introduction to Zig
    • Zig Developer
  • Linux Shell
    • Introduction to the Linux Shell
    • Linux Shell Developer
  • Interactive Training
  • Pricing
  • Brainstorm
STEMTrainingGrounds
  • Courses
    • Home
    • JavaScript
      • Introduction to JavaScript
      • JavaScript Developer
    • TypeScript
      • Introduction to TypeScript
      • TypeScript Developer
    • React
      • Introduction to React
      • React Developer
    • Python
      • Introduction to Python
      • Python Developer
    • C++
      • Introduction to C++
      • C++ Developer
    • C Language
      • Introduction to C
      • C Developer
    • Rust
      • Introduction to Rust
      • Rust Developer
    • Zig
      • Introduction to Zig
      • Zig Developer
    • Linux Shell
      • Introduction to the Linux Shell
      • Linux Shell Developer
  • Interactive Training
  • Pricing
  • Reading Grounds

Quick Links

  • About Us
  • Pricing
  • Partnership
  • Brainstorm
  • Terms
  • Privacy
  • Refunds
  • Featured on DanielLaunches

Courses

  • JavaScript
    • Introduction to JavaScript
    • JavaScript Developer
  • TypeScript
    • Introduction to TypeScript
    • TypeScript Developer
  • React
    • Introduction to React
    • React Developer
  • Python
    • Introduction to Python
    • Python Developer
  • C++
    • Introduction to C++
    • C++ Developer
  • C Language
    • Introduction to C
    • C Developer
  • Rust
    • Introduction to Rust
    • Rust Developer
  • Zig
    • Introduction to Zig
    • Zig Developer
  • Linux Shell
    • Introduction to the Linux Shell
    • Linux Shell Developer

Newsletter

Subscribe to our free monthly newsletter, for a quick update on Python, JavaScript, and React news

© 2025 - 2026 STEMTrainingGrounds. All Rights Reserved.

C Developer - Lesson 2

Lesson 2 of 40

Address-of Operator

Lesson Progress: 0%

Lesson Progress: 0%
Address-of Operator
Lesson Incomplete
← Previous: Pointers
Lesson 2 of 40
Next: Dereference Operator →

The address-of operator & is a unary operator in C that returns the memory addressof a variable. Every variable in your program lives somewhere in the computer’s memory, and & gives you the exact location (address) where that variable is stored. The address is a number that identifies a specific byte in memory. You can store this address in a pointer variable and later use the dereference operator * to access the value at that address. Understanding & is essential for working with pointers, passing arguments by reference, and understanding how C manages memory.

Code Example
#include <stdio.h>

int main() {
    int x = 5;
    printf("%d\n", *&x);
    return 0;
}

Instructions

▼ ← Click the triangle to hide or reveal instructions.

C Code Editor

Task Incomplete

Editor Input:

Editor Output:

Click "Run Code" to see the output here
  • *&x first takes the address of x with &x, then immediately dereferences it with *.
  • The dereference follows the address back to the original variable and retrieves its value.
  • *&x is equivalent to just x — it always gives the same result.
  • This snippet demonstrates that & and * are inverse operations.
  • The output is 5, the value of x.
Code Example
#include <stdio.h>

int main() {
    int x = 5;
    int y = 5;
    printf("%d\n", &x == &y);
    return 0;
}

Instructions

▼ ← Click the triangle to hide or reveal instructions.

C Code Editor

Task Incomplete

Editor Input:

Editor Output:

Click "Run Code" to see the output here
  • Two different variables x and y, even with the same value (5), live at different memory addresses.
  • &x == &y compares their addresses, which are always different.
  • The comparison evaluates to 0 (false) because they are distinct memory locations.
  • This shows that equal values do not mean equal addresses.
  • Every variable gets its own unique memory location.
Code Example
#include <stdio.h>

int main() {
    int x = 5;
    int* p = &x;
    printf("%d\n", p == &x);
    return 0;
}

Instructions

▼ ← Click the triangle to hide or reveal instructions.

C Code Editor

Task Incomplete

Editor Input:

Editor Output:

Click "Run Code" to see the output here
  • p is a pointer initialized with &x, the address of x.
  • The expression p == &x compares the value stored in p (an address) with the address of x.
  • Since p was set to &x, they are equal, so the result is 1 (true).
  • This confirms that a pointer stores the exact address of the variable it points to.
  • Comparing pointers with & is a way to check if a pointer points to a specific variable.
Code Example
#include <stdio.h>

int main() {
    int a[3] = {10, 20, 30};
    printf("%d\n", &a[0] == &a[1]);
    return 0;
}

Instructions

▼ ← Click the triangle to hide or reveal instructions.

C Code Editor

Task Incomplete

Editor Input:

Editor Output:

Click "Run Code" to see the output here
  • Array elements are stored in contiguous (adjacent) memory locations.
  • &a[0] is the address of the first element, &a[1] is the address of the second element.
  • These addresses are different because each element occupies its own space in memory.
  • &a[0] == &a[1] is 0 (false) since they are at different addresses.
  • The distance between them is the size of one int (typically 4 bytes).
Code Example
#include <stdio.h>

int main() {
    int x = 5;
    int* p = &x;
    int* q = &x;
    printf("%d\n", p == q);
    return 0;
}

Instructions

▼ ← Click the triangle to hide or reveal instructions.

C Code Editor

Task Incomplete

Editor Input:

Editor Output:

Click "Run Code" to see the output here
  • Two pointers p and q are both initialized with &x.
  • Both pointers store the same address — the memory location of x.
  • p == q compares the addresses stored in the two pointers.
  • Since they hold identical addresses, the comparison is 1 (true).
  • Multiple pointers can point to the same variable, and comparing them checks if they share the same target.
Code Example
#include <stdio.h>

int main() {
    int x = 5;
    int y = 10;
    printf("%d\n", &x != &y);
    return 0;
}

Instructions

▼ ← Click the triangle to hide or reveal instructions.

C Code Editor

Task Incomplete

Editor Input:

Editor Output:

Click "Run Code" to see the output here
  • The != operator checks if two addresses are different.
  • &x and &y are the addresses of two different variables.
  • Since x and y are separate variables, their addresses are always different.
  • &x != &y evaluates to 1 (true).
  • This reinforces that every variable has a unique memory address.

Test Incomplete

What does the & operator do in C?

Question #

1/15

Score

0/0 - 0.0 %