Input / Output Questions
Practice Input / Output MCQs with answers and explanations. Page 2 of 2.
Category
C Programming
Topic
Input / Output
Page
2 / 2
Mode
Practice
Questions
Open any question to view the answer and explanation.
C file I/O with fseek and fgets: if source.txt contains the single line "Be my friend", what does this program print?
#include<stdio.h>
int main()
{
FILE *fs;
char c[10];
fs = fopen("source.txt", "r");
c[0] = getc(fs); // read 'B'
fseek(fs, 0, SEEK_END); // go to end of file
fseek(fs, -3L, SEEK_CUR); // back up 3 bytes
fgets(c, 5, fs); // read up to 4 chars into c
puts(c);
return 0;
}
Open
View answer
Self-referential format (a classic quine-style string): what exact output does this program produce?
#include<stdio.h>
char *str = "char *str = %c%s%c; main(){ printf(str, 34, str, 34);}";
int main()
{
printf(str, 34, str, 34);
return 0;
}
Open
View answer
Understanding printf escapes: how many % signs are printed here?
#include<stdio.h>
int main()
{
printf("%%%%
");
return 0;
}
Open
View answer
Practice smarter
Solve a few questions daily and revisit weak topics regularly to improve accuracy.