One of the best features of the D40-series, as with all Nikon DSLRs, is its use of the Nikon F-mount. This method of coupling lens and body has been on continuous use since 1959.
In that time, though, two major changes have affected compatibility and function between Nikon bodies and lenses. The first was the transition to automatic maximum-aperture indexing in 1976, and then to electronic lens-body communication in 1985. The latter concerns us now.
Nikon realised in the early 1980s when experimenting with autofocus on the F3AF that a wholly-mechanical interface, as all prior Nikon lenses used, was impractical given the sort of features that would come to be incorporated into new lenses and bodies. Thus in 1985 they released a new range of "CPU Nikkor" lenses that had a microprocessor (or 'central processing unit,' hence CPU) built in that allowed full communication of data to the camera body. Initially only the selected aperture was transmitted to the camera (as the only CPU-capable bodies at that time were the F-301/N2000 and F-501/N2020), but as time went by the lenses became able to communicate a massive quantity of information about itself that enabled with various bodies features like autofocus, matrix metering and TTL flash autoexposure.
These CPU lenses are the AF and AI-P Nikkors, as well as various third-party lenses.