The muscular foot found in some form in all molluscs serves as the foot of the organism in a gastropod, but in a cephalopod it has been changed over time into an organ which can contract and shoot water for purposes of locomotion. In both cases the same ancestral structure sits in the same basic part of the organism and contains abundant muscle for locomotion, but evolution has changed the way that this works-- Especially compared to the use of the foot in bivalves for opening and closing the shell.
Work Step by Step
See Fig. 33.15 and the text on pp. 693-696 for descriptions of the foot in general and of the way that gastropods and cephalopods move. Use your imagination to see how the foot in each of the two cases mentioned in the question shows a differently evolved role for the foot but the retention of some ancestral/general structure (reliance on lots of contracting muscle).