I want to ask a question whose meaning is "what is the exact way in which X works?". Where is the most appropriate place for the adverb "exactly"?
- How exactly does X work?
- How does exactly X work?
- How does X exactly work?
- How does X work exactly?
I want to ask a question whose meaning is "what is the exact way in which X works?". Where is the most appropriate place for the adverb "exactly"?
None, in my opinion, for the meaning you provided.
And the two (three?) correct ones:
Of course, eliding the commas is common, so I'd vote the first and the fourth of your examples as the closest ones.
The reason I have trouble with the third one is the fact that "exactly", while undoubtedly an adverb, does not modify "work". It makes no sense for it to modify "work". The paraphrase for the original question would likely be "Please explain to me exactly how X works", and in this paraphrase it is clear that "exactly" modifies "explain". The fact that "Please explain to me" has been elided in the sentence while keeping the same meaning should not suddenly be able to shift the attachment of this adverb. This goes well with the fact (at least fact in the way I perceive it) that "exactly" is kept apart from the sentence by the commas.
Also, pet peeve: I hate the word "adverb". It is useless and misleading. Adverbs are modifiers that are not nouns or adjectives. They can certainly modify things that are not verbs, such as other adverbs ("very quickly"), adjectives ("reasonably pretty")...
The addition of parenthetical commas, like so:
How, exactly, does X work?
is the only correct way to convey the intended meaning, without ambiguity.
As Amadan pointed out, all four are grammatically correct, assuming for the second example that X is ambiguous or inexact, requiring or at least benefitting from the specification "exact."
I don't see the desired meaning in the question; the question is more difficult when considered for only the generic case.