There are three types of LEGO guns:
Rifles, pistols and various space blasters which are held by minifigs, and represent real world or fictional examples of those items. They are appropriately (but not necessarily realistically) scaled for minifigs. They are non-functional, and are only accessories.
Cannons and others guns designed by the LEGO group for several themes (especially Pirate and Western). These types of guns may be able to fire with a spring-based mechanism, the smaller ones firing a 1x1 cylinder brick and the larger ones, a purpose build rubber tipped missile.
Guns created by fans. These are not designed by the Lego group. They may be dangerous, and can include impressive mechanics or techniques. LEGO Heavy Weapons and Badass LEGO Guns are two books created by fans that include instructions for building 1:1 scale weapons. Eurobricks hosts the MOC Cannons Index for brick built artillery.