Is it necessary for every question to have an answer when a simple comment would suffice?
If it's on-topic, yes. The comment section is not for answers. At all. This is not a chat room or a forum. We have questions, and then their answers. In the answer section. Period.
(Say I have code that does not compile, but someone points out that I have not declared a variable.)
Then the question has become off-topic, because it's basically a "typo" or "unreproducible problem"†. At that point it may not attract an answer, but after a commenter has pointed out the situation (this being more a critique of the question than much else), the question may be downvoted and closed.
† There's some leeway here if you genuinely didn't realise you'd made a mistake, but the problem is some trivial syntax issue. I expect this to be the controversial point, especially as it can be difficult to define where the line is drawn.
"I have a code that does not compile but someone points out that I have not declared a variable"
-- there's a close reason specifically for that.foo
variable and I usebar
- clearly not duplicate"). One can write better answer instead and get upvotes...