The other groups that might be attached are denoted by R. Note that a carbon-to-oxygen bond is created while the H from the alcohol attaches to the carbonyl oxygen. Sugars have an aldehyde group and lots of alcoholic -OH groups that can react. They are along the same chain and thus form a ring. The resulting -OH has different properties from an alcoholic -OH but can react further. It cannot, however, react again with groups in its own ring.
The hemiacetal reaction is reversible. Depending on which sugar, there may be a high percentage in either an open chain or a ring. Reactions in which the aldehyde group of a sugar can participate will take advantage of this reversibility to attack the open chain form as more is made by opening the ring.