LOGBOOK

HELP

Quiz Entry - updated: 2026.07.10

How do you get the address of a variable in C?

Put & in front of a variable — &x yields a pointer to where x lives in memory, of type "pointer to x's type".

int x = 42;
// p now holds the address of x
int *p = &x;

// 42
printf("Value: %d\n", x);
// 0x7fff5fbff8ac (example)
printf("Address: %p\n", &x);
// 42
printf("Via pointer: %d\n", *p);

What & returns:

  • A pointer to the variable's memory location
  • Type is "pointer to T" where T is the variable's type
// &x has type int*
int x;
// &c has type char*
char c;
// &arr has type int(*)[5] (pointer to array!)
int arr[5];
            // But arr alone has type int* (decays to pointer)

Cannot take address of:

// ERROR: can't take address of literal
&5
// ERROR: can't take address of expression
&(x + 1)
register int r;
// ERROR: register variables have no address
&r

From Quiz: REVE1 / C Programming | Updated: Jul 10, 2026