Copyright can only be applied to "creative works". Its purpose is to protect the financial interest of the creator in such works for a period of time.
It is doubtful, but not impossible, that a court would consider student assignments and exams as "creative" in any sense. Most such things deal with "common knowledge" even though not yet known to students, perhaps.
But an assignment to "write a poem on subject X" would end up with a creative work, though, perhaps, of questionable quality. Likewise some "open ended questions" might qualify, even in something like CS.
But an instructor would have no rights to any creative work produced solely by a student. If it is subject to copyright at all, the rights are held by the creator.
See: https://copyright.uslegal.com
The separate question, unrelated to copyright, is whether you have a right to feedback on what you write in a test. My opinion is that you do, indeed, and any sensible system will have a way to provide that. It doesn't mean, however, that you have a right to carry away a copy of what you turned in, but you should at least have an opportunity to speak with a professor on the quality of what you write there.
And if you think something you write for an exam is worthy of publication, there is no reason that you can't take those ideas and produce something based on it. For that, you will have copyright.