File Handling in C language MCQs

@T-Bone

This question paper focuses on the "File Handling" of the C programming. These Multiple Choice Questions (mcq) should be practiced to improve the C programming skills required for various interviews (campus interview, walk-in interview, company interview), placement, entrance exam and other competitive examinations.

This question paper focuses on the "File Handling" of the C programming. These Multiple Choice Questions (mcq) should be practiced to improve the C programming skills required for various interviews (campus interview, walk-in interview, company interview), placement, entrance exam and other competitive examinations.

Questions

1. Which of the following true about FILE *fp

Mark the correct option

2. Which of the following mode argument is used to truncate?

Mark the correct option

3. The first and second arguments of fopen() are

Mark the correct option

4. FILE is of type ______

Mark the correct option

5. fseek() should be preferred over rewind() mainly because

Mark the correct option

6. FILE reserved word is?

Mark the correct option

7. For binary files, a ___ must be appended to the mode string.

Mark the correct option

8. Which of the following statements about stdout and stderr are true?

Mark the correct option

9. Which type of files can’t be opened using fopen()?

Mark the correct option

10. When a C program is started, O.S environment is responsible for opening file and providing pointer for that file?

Mark the correct option

11. If there is any error while opening a file, fopen will return?

Mark the correct option

12. It is not possible to combine two or more file opening mode in open () method.

Mark the correct option

13. What is the return value of putchar()?

Mark the correct option

14. Which is true?

Mark the correct option

15. What is the purpose of "rb" in fopen() function used below in the code? FILE *fp; fp = fopen("demo.txt", "rb");

Mark the correct option

16. Which files will get closed through the fclose() in the following program? void main() { FILE *fp, *ft; fp = fopen("a.txt", "r"); ft = fopen("b.txt", "r"); fclose(fp,ft); }

Mark the correct option

17. When fopen() is not able to open a file, it returns

Mark the correct option

18. getc() returns EOF when

Mark the correct option

19. What is the output of this program? #include <stdio.h> int main(){ FILE *fp; char *str; fp=fopen("demo.txt","r");// demo.txt :you are a good programmer while(fgets(str,6,fp)!=NULL) puts(str); fclose(fp); return 0; }

Mark the correct option

20. What is the output of this program? #include <stdio.h> int main(){ char c; FILE *fp; fp=fopen("demo.txt","r"); while((c=fgetc(fp))!=EOF) printf("%c",c); fclose(fp); return 0; }

Mark the correct option

21. What is the output of this program? #include <stdio.h> int main(){ char c; FILE *fp; fp=fopen("demo.txt","a+"); // demo.txt : hello you are reading a file fprintf(fp," demo"); fclose(fp); fp=fopen("myfile.txt","r"); while((c=fgetc(fp))!=EOF) printf("%c",c); fclose(fp); return 0; }

Mark the correct option

22. A data of the file is stored in …

Mark the correct option

23. Select a function which is used to write a string to a file…

Mark the correct option

24. Select text file in which data is stored in

Mark the correct option

25. We should not read after a write to a file without an intervening call to fflush(), fseek() or rewind()

Mark the correct option

26. Offset used in fseek() function call can be a negative number.

Mark the correct option

27. Will the following program work? #include <stdio.h> int main() { int i=3; printf("i=%*d", i, i); return 0; }

Mark the correct option

28. stderr, stdin, stdout are FILE pointers

Mark the correct option

29. which Is data type of file pointer is….

Mark the correct option

30. In fopen(), the open mode "wx" is sometimes preferred "w" because. 1) Use of wx is more efficient. 2) If w is used, old contents of file are erased and a new empty file is created. When wx is used, fopen() returns NULL if file already exists.

Mark the correct option

31. A file written in text mode can be read back in binary mode.

Mark the correct option

32. A file written in text mode can be read back in binary mode.

Mark the correct option

33. A text stream is an ordered sequence of characters composed into lines, each line consisting of zero or more characters plus a terminating new-line character.

Mark the correct option

34. While calling the fprintf() function in the format string conversion specifier %s can be used to write a character string in capital letters.

Mark the correct option

35. Select text file in which number will take.

Mark the correct option

36. Which is true about getc.getc returns?

Mark the correct option

37. What is the meant by 'a' in the following operation? fp = fopen("letsfindcourse.txt", "a");

Mark the correct option

38. What does the following segment of code do? fprintf(fp, "Copying!");

Mark the correct option

39. _____removes the named file, so that a subsequent attempt to open it will fail.

Mark the correct option

40. EOF is an integer type defined in stdio. hand has a value ____________

Mark the correct option