First officer

A first officer (aka executive officer, XO, and number one) is the second-highest ranking officer aboard a starship or space station after the commanding officer. They take command if the commanding officer is unable to. If the first officer is also unable to take command, the second officer is in charge, followed by the third officer, and so on.
== Typical rank ==
In Starfleet, the position was usually held by an officer with the rank of commander or lieutenant commander.
== Duties ==
In Starfleet's early period of existence, the first officer would accompany the captain on landing parties, depending on the situation. By the 24th century, however, it was the first officer who usually led away teams while the captain remained on the ship.
In the 22nd and 23rd centuries, the first officer served as a department head first and the executive officer second (similar to the second officer and third officer) and only took command when the captain left the bridge, as such, there was no first officer's station as there would be in the 24th century, as the XO would alternate between the command chair and their station as a department head.
Noted functions of the first officer aboard a Federation starship were: 
* The primary role of the second-in-command was to carry out the decisions of the Captain. (TNG: "Gambit, Part II")
** Obey and implement the captain's orders. (TOS: "The Enterprise Incident"; TNG: "Gambit, Part II"; DS9: "Paradise Lost")
** To be informed, insomuch as to know everything the captain knew. (TNG: "Code of Honor") As well as had full security clearance to possess such knowledge. (TNG: "Samaritan Snare")
** Attending important meetings and briefings with the captain. (Star Trek Into Darkness)
** Take command of the vessel in the event of the captain's absence, incapacitation or death. (TOS: "The Squire of Gothos", "Journey to Babel"; VOY: "Before and After", "Scorpion, Part II", "Night", "Tsunkatse", "Unimatrix Zero", "Unimatrix Zero, Part II"; TNG: "The Battle", "The Best of Both Worlds", "The Best of Both Worlds, Part II", "Tapestry", "Gambit, Part I")
* To point out any actions that may be mistakes by a commanding officer. (Star Trek: The Motion Picture, TNG: "Chain Of Command, Part II", "The Pegasus"; DS9: "Paradise Lost", "To the Death" VOY: "Alliances", "Scorpion", "Year of Hell", "The Omega Directive", "Night", "Infinite Regress", "Equinox, Part II", "Unimatrix Zero", "Shattered")
* To safeguard the lives of the ship's crew, particularly the captain. (TNG: "In Theory" VOY: "Shattered")
* Act as the officer in charge of personnel. (VOY: "Day of Honor")
** Preparing and issuing duty rosters. (VOY: "The Gift", "Tsunkatse", "Endgame")
*** Following the promotion of Acting Ensign Wesley Crusher in 2364, Captain Jean-Luc Picard told Crusher, that while he waited for his acceptance into Starfleet Academy, "you will learn this ship–every operation, every function," and that Commander William Riker would prepare a duty schedule for him, "heavy on study". (TNG: "Where No One Has Gone Before")
*** According to Captain Kathryn Janeway, if a member of the crew needs to leave their post, they are required to inform the first officer. (VOY: "Human Error")
** Coordinate personnel transfers between departments. (TNG: "Lessons")
** Working with the chief medical officer or counselor on crew evaluations, (TNG: "Man Of The People", "Lower Decks") as well as crew discipline. (VOY: "Lifesigns")
** Supervise subordinates.
*** When Hoshi Sato requested the help of T'Pol, Sato expressed her frustration with how frequently T'Pol was looking over her shoulder, double-checking her log entries, and translations. While T'Pol felt she was just doing her job, and explained how she held Sato to a high standard because "I know you're capable of achieving it." (ENT: "Vox Sola")
** Managing the ship's resources, including systems allocation. (TNG: "Lessons")