Why do i have a random result on this template?

The template instantiated will be

int* f(int* x, int y)
{
    return x + y;
}

Therefore you’ll be doing pointer arithmetic, then dereferencing a pointer in which you did not allocate, which happens to be incremented 23 addresses past a.

It is essentially as if you’d called

*(new int(23) + 23);

Leave a Comment