How does one differentiate between pointers and references at runtime? For example, if I wanted to free a pointer of a data type without knowing whether it were a pointer or not how would I do so? Is there any method to tell if a variable has been allocated on the stack or through malloc()?
void destInt(int* var)
{
free(var);
}
int num = 3;
int &numRef = num;
int* numPtr = (int*)malloc(sizeof(int));
*numPtr = num;
destInt(&numRef); //Syntactically correct but generates invalid pointer()
destInt(numPtr); //Fine syntactically and logically