It's wrong because you did this
*ptr = 10;
before you did this
ptr = somewhere;

You can't just declare a pointer and magically hope it points to somewhere useful. You have to do it yourself. Chaos and madness result if you don't.

int a;
ptr = &a;
Gets you a pointer to ONE integer

int a[10];
ptr = a;
Gets you a pointer to TEN integers

ptr = malloc( sizeof(*ptr) * 10 );
This too is a pointer to 10 integers. But at some point, you need to do
free( ptr );