Will RAMPS able to control 4 stepper motors
There is no problem with using 4 motors instead of 5. The 5th slot is provided to enable use of a second extruders, but many people only have a single extruder printer and leave the 5th slot unused.

how will Marlin figure out which slot the extruder is connected

Which stepper motor is in which slot is something you can configure in the firmware. There is no way for the firmware to &quot;figure it out&quot; without help.
It is quite involved to change it in the firmware, so it is best to follow the default placement. You can easily find wiring diagrams for RAMPS (showing the default assignment of motors to slots) on various resources such as the RepRap wiki.