If it is allocated on the stack of a function than it can not be returned to the caller. You will have to allocate the memory from the free store.
Code:
int blah(){
      int x = 5
      return x;
}

int main(){

    int y = blah();
    cout<<y<<endl;
    return(0);
}
If your going to be mean at least be right. You can allocate data on the stack of a function and return its value to the caller which is what the original code did and what this code does. Yes if you returned a pointer this way it would be rather pointless however in returning a value like above the compiler will generate a temp variable to hold the value between the function terminating and then the assignment in the calling block.