Simple, a switch that connects to endpoints (PCs) together on a common VLAN, as depicted in your picture, the switch would learn the MACs of PC1 and PC2. The CAM or MAC Address table would get populated with a MAC to Port binding, the port that learned the MAC address. So when PC1 would send a frame out to the switch, the switch looks at the layer 2 header and sees the destination as PC2, looks in its CAM table and finds an entry. The switch then knows which port to send the frame out to.
If you were Layer 3 Routing, then the layer 2 header would get stripped off at the layer 3 gateway and would be rebuilt as the layer 3 gateway would forward the frame out the exit interface to the destination. Layer 2 headers are only maintained inside the same broadcast domain, once traffic exits the broadcast domain, the layer 2 header needs to be rewritten on a per hop basis.
Rob Riker, CCIE #50693, CCNP Service Provider, VCP5-DCV