Practice mode C Language

Which fopen() mode opens a file for both reading and writing, creating it if needed and truncating it if it already exists?

Correct answer C. "w+"

Explanation

"w+" creates the file if needed and truncates it to zero length, then allows both reading and writing. "r+" also allows both but requires the file to exist and keeps its contents, while "a+" keeps contents and sends writes to the end. "rw" is not a valid standard mode. When switching between reading and writing on such a stream, call fflush or fseek in between.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.