This set of C Multiple Choice Questions & Answers (MCQs) focuses on “File Access – 2”.
Pre-requisite for this C MCQ set: Advanced C Programming Video Tutorial.
1. Which of the following fopen() statements are illegal?
a) fp = fopen(“abc.txt”, “r”);
b) fp = fopen(“/home/user1/abc.txt”, “w”);
c) fp = fopen(“abc”, “w”);
d) none of the mentioned
View Answer
Explanation: None.
2. What does the following segment of C code do?
fprintf(fp, "Copying!");
a) It writes “Copying!” into the file pointed by fp
b) It reads “Copying!” from the file and prints on display
c) It writes as well as reads “Copying!” to and from the file and prints it
d) None of the mentioned
View Answer
Explanation: None.
3. What is FILE reserved word?
a) A structure tag declared in stdio.h
b) One of the basic data types in c
c) Pointer to the structure defined in stdio.h
d) It is a type name defined in stdio.h
View Answer
Explanation: None.
4. What will be the output of the following C code?
#include <stdio.h>
int main()
{
FILE *fp = stdin;
int n;
fprintf(fp, "%d", 45);
}
a) Compilation error
b) 45
c) Nothing
d) Depends on the standard
View Answer
Explanation: None.
5. What will be the output of the following C code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE *fp = stdout;
int n;
fprintf(fp, "%d", 45);
}
a) Compilation error
b) 45
c) Nothing
d) Depends on the standard
View Answer
Explanation: None.
6. stdout, stdin and stderr are ________
a) File pointers
b) File descriptors
c) Streams
d) Structure
View Answer
Explanation: None.
7. Which of the following statements about stdout and stderr are true?
a) Same
b) Both connected to screen always
c) Both connected to screen by default
d) stdout is line buffered but stderr is unbuffered
View Answer
Explanation: None.
8. What will be the output of the following C code?
#include <stdio.h>
int main()
{
FILE *fp = stdout;
int n;
fprintf(fp, "%d ", 45);
fprintf(stderr, "%d ", 65);
return 0;
}
a) 45 65
b) 65 45
c) 65
d) Compilation error
View Answer
Explanation: None.
9. What will be the output of the following C code?
#include <stdio.h>
int main()
{
FILE *fp = stdout;
int n;
fprintf(fp, "%d\n ", 45);
fprintf(stderr, "%d ", 65);
return 0;
}
a) 45 65
b) 65 45
c) 65
d) Compilation error
View Answer
Explanation: None.
10. What will be the output of the following C code?
#include <stdio.h>
int main()
{
FILE *fp = stdout;
int n;
fprintf(fp, "%d ", 45);
fflush(stdout);
fprintf(stderr, "%d", 65);
return 0;
}
a) 45 65
b) 65 45
c) 45
d) Compilation error
View Answer
Explanation: None.
Sanfoundry Global Education & Learning Series – C Programming Language.
To practice all areas of C language, here is complete set of 1000+ Multiple Choice Questions and Answers.
- Practice BCA MCQs
- Check C Books
- Apply for Computer Science Internship
- Watch Advanced C Programming Videos
- Apply for C Internship