Rather, in a way, you have been both right.
While there are subtle differences in context of pragmatics as below, it should not be the bases of rejecting the answer. It rathers looks like the teacher deliberately marked it as wrong, as it did not literally matched the given answer.
IMHO, instead of asking, you should rather stand up for yourself and confront your teacher. The fact you had to ask about it is evidence of your failure to be confident in your knowledge.
The right order A and B has two points of view(POV):
POV of logic: The order A and B is equivalent to B and A.
POV of pragmatics: A and B is usually used as "A is the main descriptor" while "B is the modifier". In similar sense as if A was a noun and B was a descriptive adjective.
- Organic compounds are primarily compounds of carbon.
- Not all carbon compounds are organic ones, but all organic compounds contain carbon.
- Most of organic compounds contain hydrogen, but not always.
- Typical exceptions are per-halogenated hydrocarbons, or mellitic anhydride $\ce{C12O9}$, containing just carbon and oxygen.
- It is therefore natural to start with carbon, when specifying a subclass of organic compounds.
So, primarily, in context of organic compounds, "Hydrocarbons are compounds of carbon and ....."
Now, hydrogen comes as the modifier, specifying which carbon compounds are hydrocarbons.
Therefore, "Hydrocarbons are compounds of hydrogen and carbon." is logically right, pragmatically not exactly wrong, but suboptimal and less usual.