A guitar is a 6 or 12 stringed instrument that is played by plucking or strumming the individual strings
When a string is plucked or strummed, the string vibrates, which creates a sound wave. The motion of the string vibrating moves the air molecules around which is how sound is created. Normally, this sound alone isn't loud at all, but the hole in the body of the guitar amplifies the sound allowing it to be heard.
When a finger is pressing on the fretboard, the string is making comtact with the nearest truss rod(the steel rod on the fretboard). Then when the string is plucked, it plays the note the string is touching.