I agree with the basic thoughts behind the answer posted by Sobrique. That said, I'd like to offer some additional advice:
I definitely agree that one should try to avoid answering bad questions, for the reasons stated in the other answer. But, the word "bad" encompasses so many different possibilities that that approach is at best a broad rule of thumb.
If you do feel that you can usefully answer the question, that means you've seen something in the question that others have not. This can happen, generally because you have more expertise in the topic and/or have run into the particular issue or misunderstanding the OP is trying to describe.
But the question might still be a bad question in some way. Sobrique's answer suggests only answer if your answer "will be found, based on the starting question". I'll offer an alternative: yes, it's important that your answer can be found by those needing it. But remember that you can edit other people's questions.
So it's not so important that the "starting question" itself is good. What matters if whether you can make it good. If you feel you can answer the question, then you may be (and probably are) in a unique position to also improve the question. In fact, I would say that if you feel you're able to usefully answer a question that is otherwise considered bad by the community and intend to go ahead and do so, that you should consider yourself obligated to also edit the question. That way, you are in fact answering a good question (*).
Doing so will reveal in the question the elements that you yourself were able to perceive even as others could not, as well as will fix other issues that likely exist with the question, including grammar and formatting errors, but also even including a lack of a good code example. This will not only make the question more searchable, in making it more comprehensible it may lead to allowing other good answers to the question as well, complementing your own.
As Sobrique's pointed out, the broader goal of SO is not so much to help individual people asking questions (though that's an important secondary goal), but rather to maintain and curate as large a collection as possible of searchable, useful questions and answers. That goal is only half-achieved if all you do is answer a bad question. The rest of the goal requires that the bad question be turned into a good question.
(*) Unfortunately, SO doesn't have a mechanism for notifying downvoters that a question has been edited and may no longer warrant the downvote. So such questions always will have its early history dragging it down. But that is IMHO not a reason to avoid trying to improve the question.