A ranking officer, also known as a superior officer, was a relative leadership position within a chain of command that one officer held over another officer or group of officers 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 for a military unit like a starship was usually referred to as the commanding officer. The ranking officer for a duty shift on the bridge of a starship was known as a duty officer. Also, the term was occasionally used by Starfleet personnel to refer specifically to officers of a high rank. (DS9: "Homefront")
Determinants for a ranking officer in Starfleet were similar to the chain of command, which included (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 she felt that the Starfleet engineering officers might have had 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, trying 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."
- - The Doctor (as the Emergency Command Hologram) and Harry Kim, discussing who will be in command of Voyager during Commander Chakotay's absence (VOY: "Workforce")