Train coaches of most of the trains are usually interlinked and you can get through whichever coach you want but for some coaches (especially in 1A and EC) passengers are not allowed to enter. Generally, a pantry car is placed in between trains so that it will be easily accessible from all coaches. Although passengers are not allowed to enter the pantry car, they can ask for whatever they want by standing outside the door.