Lesson 2 of 40
Lesson Progress: 0%
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.
#include <stdio.h>
int main() {
int x = 5;
printf("%d\n", *&x);
return 0;
}Instructions
▼ ← Click the triangle to hide or reveal instructions.Task Incomplete
Editor Input:
Editor Output:
*&x first takes the address of x with &x, then immediately dereferences it with *.*&x is equivalent to just x — it always gives the same result.& and * are inverse operations.5, the value of x.#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.Task Incomplete
Editor Input:
Editor Output:
x and y, even with the same value (5), live at different memory addresses.&x == &y compares their addresses, which are always different.0 (false) because they are distinct memory locations.#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.Task Incomplete
Editor Input:
Editor Output:
p is a pointer initialized with &x, the address of x.p == &x compares the value stored in p (an address) with the address of x.p was set to &x, they are equal, so the result is 1 (true).& is a way to check if a pointer points to a specific variable.#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.Task Incomplete
Editor Input:
Editor Output:
&a[0] is the address of the first element, &a[1] is the address of the second element.&a[0] == &a[1] is 0 (false) since they are at different addresses.int (typically 4 bytes).#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.Task Incomplete
Editor Input:
Editor Output:
p and q are both initialized with &x.x.p == q compares the addresses stored in the two pointers.1 (true).#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.Task Incomplete
Editor Input:
Editor Output:
!= operator checks if two addresses are different.&x and &y are the addresses of two different variables.x and y are separate variables, their addresses are always different.&x != &y evaluates to 1 (true).Test Incomplete