Federal Flight Deck Officers are pilots, copilots, flight engineers, and navigators (if that position still existed in modern aircraft) who are specially trained as law enforcement officers. They are allowed to keep loaded weapons in the cockpit. However, the TSA (their parent organization) has refused to allow them to do so outside of the cockpit or carry the weapons in holsters like any other law enforcement officer. This is a far greater security risk than it seems to many people, as is evident by the instances of passengers mistaking Federal Flight Deck Officers' bags, containing weapons, for their own.
A flight with a Federal Flight Deck Officer onboard is less than a tenth of the price to the United States government of a flight with a Federal Air Marshal onboard. They are given much of the same training and certification, but are not primarily law enforcement officers. They fulfill the same mission as Federal Air Marshals: prevention of hijacking. However, they have been treated with incredible disdain since the program's inception a few years ago.