Executive Officer (or First officer, or XO for short) is the second-in-command of a starship, a space station, or any other Starfleet unit. In most cases, an XO has the rank of Commander or Lieutenant commander. But for very large single-command assignments, officers with the rank of Captain are assigned as XO's to flag officers or more senior captains, or for very minor single-command assignments, XO's have the rank of Lieutenant.
The XO's chief duty is to carry out the CO's orders. One of the Executive Officer's chief responsibilities is the training, discipline and management of the ship's personnel. In that capacity, the XO makes recommendations for promotions and transfers based on inputs from the crewmember's department head.
The XO is operationally the ship's second in command, and will immediately assume command if anything renders the Commanding Officer unfit for duty. The XO is often the closest officer to the CO due to the two generally being the most senior officers aboard. As such, the XO also often acts as the captain's conscience and confidante. The XO will act as ship's Counselor if the ship doesn't have an officer specifically assigned to that duty. It is another primary duty of the First Officer to spearhead away teams so that the CO can remain safe in the confines of the bridge. The XO is the chief administrative officer on the ship and frequently must act as liaison between department heads. It is generally understood also, that a ship's XO is a commanding-officer-in-training, because the successful completion of an Executive Officer tour is a key prerequisite for a command of ones own. Finally, the XO is specifically tasked by Starfleet Command to determine when a CO oversteps his/her bounds.