Can a pointer ever point to itself?

void* p = &p;

It’s not terribly useful, but structs that point to themselves are useful in circular lists of length 1:

typedef struct A {
  struct A* next;
} A;

A a = { &a };

Per your exact example, I believe you meant:

int* a;
int b = (int)&a;
a = (int*)b;

// which can be simplified to:
int* a = (int*)&a;

Leave a Comment