The head of state is the highest official position in a country. It is the office in which the sovereignty of the state is formally vested in. All government work is carried out in the name of the head of the state.
Nobody appoints a head of stare. Instead, in a republic, the head of state, usually called the President, is either directly elected by the people (as in USA) or indirectly by the legislature (like in India). In monarchies, the head of state is the King or Queen who acquires office through hereditary rights.
If the head of state is directly elected or is a dictator, then he functions as the most important executive official in government. If the President is indirectly elected or if the monarchy is constitutional, then his role is mostly ceremonial with real executive power residing in the office of the prime minister.