Can you lock the f stop on a the Nikon D5100?
I'm not even sure if that is possible or not.
Yes. Set the dial to A, and you can set the aperture which the camera chooses a shutter speed. Set it to M and you manually select aperture and shutter speed.
First answer is right. Aperture Priority mode.
As the first answer says, by putting the mode dial in position "A" you can lock it - to a point! It will still change however if you are using a zoom lens that has a variable maximum (wide - low f/number) aperture.
So, you put your camera in to "A"perture priority mode, with the lens at 18mm and use the adjustment dial to set the aperture at f/3.5. You then zoom your lens to 55mm, but at that focal length the lens has a maximum aperture of f/5.6, your lens will automatically set itself to this value during the zoom taking place. If you now zoom back down to 18mm, the lens will hold that f/5.6 setting unless you change it.
Hope that makes sense…
You should read your owner manuel, it come with the camera for good reasons. "A" "M".