Why are cimetidine and ranitidine better antacids than sodium hydrogen carbonate, magnesium or aluminium hydroxide?

Antacids neutralise the excess acid produced in the stomach but their prolong use can cause the production of excess acid in the stomach which is harmful and may result in ulcers. Cimetidine and ranitidine work without such side effects as they prevent interaction of histamine with the receptors of the stomach wall as histamine stimulates the secretion of acid.