The pilot in command of an aircraft is the person who is ultimately responsible for the safety of the aircraft and all aboard, as well as the one with command authority over the aircraft's disposition - flight, configuration, etc. For the U.S. Federal Aviation Administration's definition of the pilot in command (sometimes abbreviated PIC) we turn to Federal Aviation Regulations Part 91, which is also found as Title 14, U.S. Code of Federal Regulations - Part 91.
FAR Part 91 § 3, "Responsibility and authority of the pilot in command" states:
- The pilot in command of an aircraft is directly responsible for, and is the final authority as to, the operation of that aircraft.
- In an in-flight emergency requiring immediate action, the pilot in command may deviate from any rule of this part to the extent required to meet that emergency.
- Each pilot in command who deviates from a rule under paragraph (b) of this section shall, upon the request of the Administrator, send a written report of that deviation to the Administrator.
In practical terms, this means that the person acting as PIC is responsible for the aircraft's flight and safety, but that in an emergency the PIC is specifically authorized to break any of the regulations for flight listed in Part 91 in order to meet their responsibility for the safety of the passengers and aircraft (in that order). For example, landing an airplane on an active roadway is definitely a no-no. However, if the airplane is in distress (the typical reason is engine trouble) then the PIC is specifically authorized to land the airplane on a road if that is the only way to reasonably get it safely on the ground. The final part, c, requires all such emergency deviations to be acknowledged and documented if the FAA requests such.
Declaring an emergency is the responsibility of the PIC or authorized crew, and should always be done (if practical) before taking actions which may violate FAR 91. However, if communications are not possible or there is no time, the PIC should follow the following priority list: aviate, navigate, communicate. If you need to aviate first, do it!
Time spent as pilot in command is logged as such in a pilot's logbook, and various requirements for piloting may specifically refer to the pilot's number of PIC hours rather than flight hours in general. While you are learning to fly, when your CFI is in the airplane with you you may log flight time, but not PIC time - the CFI is the PIC even if they're sitting in the right hand seat. When you first solo, you will log your first PIC time! As noder NJNate points out, once you have a pilot's license, if you are training for additional certifications or endorsements with a CFI in the aircraft, you may log that time as PIC time since you are legally able to execute the function of PIC (once you have a license, you may command aircraft which have passengers in them, in this case the CFI). You should log that time as 'Dual Received' time as well as 'Pilot in Command' time to show you received training.