How Stringed Instruments Work
Guitars, like other string instruments, primarily generate sound through the resonance of their strings. The strings have elasticity (ie they can bend) and have tension applied to them so that they are suspended in a straight line - their resting state. Any force that moves the string outside its resting state increases the amount of tension on the string - this is called exciting the string. It will try to return to its resting state; however, its momentum will actually carry it past that point, like a pendulum. Thus, the string resonates back and forth, slowly losing energy by transferring it to the body (as well as generating heat inside the string).
Strings resonate at a certain pitch, depending on the thickness, length, and the amount of tension applied to the string. The thicker, longer, and lower the tension, the lower the pitch, and vice versa. It is important to realize that this simple formula isn't absolute - there are some very nuanced complexities to the physics involved; however, the relationships are good enough to be perceived as completely accurate. For guitar and most instruments, the strings have different thicknesses but relatively the same tension. Thus, the thicker strings have lower pitches than the thinner ones. The even tension makes playing (and especially bending) the strings have a consistent difficulty from one to the next. The primary method of altering pitch is by shortening the string length by pressing the strings against the frets or fingerboard. However, other methods are also used - for instance, in electric guitar a whammy bar or bending technique may be used to reduce or increase string tension; and in piano, each key relates to its own string of a fixed length.
The strings themselves generate very little sound - they are physically incapable of moving the volume of air necessary to perceive sound (at least not for an audience or with a good tone). The string resonance is turned into sound by a transducer.
In an acoustic instrument, the string resonance is transferred to the body, which usually consists of 2 large flat surfaces. The one connected to the strings vibrates and creates sound, like a large speaker. Some of the sound is directly projected outwards while some of it is directed to inside the body. The sound inside the body can reflect off the parallel surfaces and come out the sound hole(s) - this sound is fuller and darker, strengthening the fundamental frequencies played as well as balancing the overall frequency response of the instrument. This is due to the size of the body, which is large enough for high frequencies to cancel out as they reflect, while lower frequencies do not. The relatively small size of the sound hole forces the sound to reflect inside the body before leaving, where it can form constructive harmony, preventing it from sounding thin.
In electric instruments, the body serves simply as an anchor. Thus, we see lots of types (and weights) of wood used, as well as body shapes and sizes in electrics. Pickups are used to convert the string resonance into electrical current, which is then sent to an amplifier which drives a speaker. (There are also acoustic-electric instruments that are essentially acoustic instruments with added pickups.)
Strings can be excited in a variety of manners. For guitar, the strings are typically excited with a plectrum (pick) or with the fingers. Most classical stringed instruments (violin, viola, bass) are excited with a bow, which rubs horsehair against the strings, although they are sometimes plucked (pizzicato) with fingers. Piano uses hammers to strike its strings, similar to the technique of slapping, which is common in modern bass. The strings can also be excited by sound waves; examples include yelling at them or feedback from an amplified speaker connected to the instrument. Finally, magnetic strings (as used by electric guitars) can have resonance induced through electromagnetic force, such as through an E-Bow or Sustainiac device.