Practice mode C Language

What is printed by this C code: FILE *f = tmpfile(); fputs(“abc”, f); printf(“%ld”, ftell(f)); fclose(f);?

Correct answer C. 3

Explanation

tmpfile creates a temporary binary file opened in "wb+" mode. After fputs writes the three characters a, b and c, the file position indicator has moved three bytes, so ftell returns 3. fputs does not write the string's null terminator or add a newline, which is why 4 is wrong. The temporary file is removed automatically when closed or when the program ends.

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.