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.
Answer checked How we write and check questions
Discussion