Yes you can do that. Most european car rental companies will allow that. Herz, Sixt/Budget, Avis etc will all have no problem with that.
A rental car in Germany will cost you around 40+ (++ depeding on the car) per day.
Driving it and dropping it in Hungary will cost you 250+ (++ ...) per day.
So if you drive from the German-Austrian border to Hungary in half a day, the price difference is not too bad. If you drive it from the Danish border to Hungaria, it becomes stupidly expensive.
To sum it up: Since you gave us neither the type of car you want, nor the place where you start off, nor where you drop the car, I can only make the general suggestion that it will be cheaper to rent a car anywhere in Germany, drive as far as you can to the border, maybe even to Austria, drop the car there, rent a new one and drive the rather short last distance either by another rental car or even by train.