For the purpose of voting, no person shall be deemed to have gained or lost a residence by reason of his presence or absence while engaged in the civil or military service of this state or of the
United States, or in the navigation of the high seas or the waters of the state or of the United States, or while a student of any institution of learning, or kept in a poor house or other asylum at public expense, or confined in public prison.