Why did many soldiers use a hand gun?

Handguns were used in the first world war extensively because they were easier to wield in trench warfare.
Since then they have been primarily issued to troops who for confined space reasons would have trouble carrying a rifle. For example Armored crewmen, transport drivers, clerical personnel. Submachineguns are also commonly issued in many armies for these reasons.