A ranking officer (also known as a superior officer) is a relative leadership position within a chain of command that one person may hold over one person or a group of people within a situational context.
Starfleet utilized this system, entrusting a ranking officer with the command decisions for various circumstances, including departments aboard a starship and leads on away missions. The ranking officer normally for a military unit like a starship is usually referred to as the commanding officer. The ranking officer for a duty shift on the bridge of a starship is known as a duty officer. Also, the term is sometimes used by Starfleet personnel to refer specifically to officers of a high rank. (DS9: "Homefront")
Determinants for a ranking officer in Starfleet are similar to the chain of command, which include (in no particular order): rank, seniority, Starfleet division, direct orders from a flag officer or Starfleet Command, and Starfleet regulations.
Examples of ranking officers
Lieutenant Malcolm Reed was the ranking officer of the Enterprise while Archer, T'Pol, and Commander Charles Tucker III were incapacitated. (ENT: "Vox Sola") Ensign Travis Mayweather was next in the chain of command after Lt. Reed, and ahead of Ensign Hoshi Sato. (ENT: "Cold Front")
In 2267, Commodore Matt Decker, the highest ranked officer aboard the USS Enterprise at the time, chose to enact Starfleet Order 104 and became the commanding officer before he was relieved by Spock. (TOS: "The Doomsday Machine")
Later in 2267, Commodore Stocker, despite his lack of field experience, was the ranking officer aboard the Enterprise and took command after the crew was infected by a radiation disease. (TOS: "The Deadly Years")
In 2371, after Captain Kathryn Janeway disappeared during an away mission, The Doctor wished to speak with the highest ranking officer aboard the USS Voyager who was not missing in regards to personnel changes aboard the vessel without his prior knowledge. (VOY: "Time and Again")
Later in the same year, Captain Janeway was concerned about making B'Elanna Torres the chief engineer aboard Voyager as the Starfleet engineering officers may have difficulty accepting a Maquis as their superior officer. (VOY: "Parallax")
"On your feet, that's an order!"
"You can't give me orders, we're the same rank."
"I'm a bridge officer, and I have seniority."
"Yeah, by about two days!"
- - Tom Paris tries to convince B'Elanna Torres to continue moving as they traverse a cold environment within the Nyrian biosphere vessel (VOY: "Displaced")
"I want you to take Seven. Since she has no rank, you clearly outrank her."
- - Captain Janeway to Ensign Harry Kim, after he expressed concern of Janeway assigning a higher-ranking officer to "his" away mission (VOY: "Nightingale")
"I assumed I'd be in charge during your absence, commander."
"An Emergency Command Hologram programmed with over two million tactical subroutines outranks an ensign."
"A few words to the computer and this ensign can delete those subroutines."