20Gal LONG is generally considered the minimum sized aquarium for an adult cornsnake. So yes, you can house a corn in a 40 gallon just fine. Reguardless of how big the cage (as long as it's not too small), corns will generally be happy as long as they have enough places to hide.