When engaged in exercises afloat or participating in encampments for instructions ashore, and when serving on general courts-martial, officers and men shall receive the same pay as is at the time allowed by law to those holding similar positions in the United States navy.