The D50 is not an older D40 or D40x, although those 2 models seem to have replaced it in the lineup.
The key differences: - D50 has an autofocus motor built into the camera body. Neither the D40 nor the D40x has this motor, which ultimately means the D50 will autofocus on all Nikon AF lenses, while D40/x requires newer Nikon AF-S lenses for autofocus. - D40 & D40x share a smaller camera body & grip, so this might be a plus or minus depending on the size of your hands. - D50 has 5 autofocus points while D40 & D40x has 3. - D50 has a top-mounted LCD that shows all important settings at a glance. - D40 & D40x have no top LCD but a bigger and better rear LCD. - D40 shares the same 6MP sensor as D50 but D40 has newer noise reduction algorithms, so the D40 has better high-ISO (low light) noise performance. - D40x shares a 10MP sensor with D80 & D200 - D50 has more external buttons so there's more features at your fingertips where D40/x might have you diving into a menu to change settings. - D50 has auto exposure bracketing, D40/x doesn't
This list could go on and on into obscure features you might not understand. For lens compatibility, it's not simple but the lenses that come with D40 & D40x work perfectly on D50. As I said above, D50 will autofocus on older AF & AF-D Nikon lenses where D40 won't. There are some very old manual focus lenses that can be mounted on D40/x and not D50 but I doubt these are lenses you're asking about.