Neither of the two answers provided give the full answer, both touch on it, from different perspectives, but neither address it completely.
Given your description, it sounds as though the question is being asked in the context of a lab strain.
Plasmids for ampicillin resistance carry the AmpR gene on them which encodes for the enzyme beta-lactamase.
Beta-lactamase hydrolyses the beta-lactam ring, which is the 4-membered ring that has the carbonyl group and the nitrogen in the ring.
It then decarboxylates the carboxy group that results from the hydrolysis, removing the threat to the bacteria's ability to make cell walls, as Chris explains.
As both ampicillin and penicillin are closely related beta-lactam antibiotics, and have the same beta-lactam ring moiety which is the substrate of beta-lactamase, both molecules are neutralized by the enzyme and the bacterial cells will divide and not be inhibited from forming a cell wall.