Notice: Due to an ongoing migration of our storage and publishing system, material requested since last month will not be uploaded for the time being, and new requests are paused. All existing notes remain available.

Unit 6 MCQs File Handling

CAP1008 — C Programming 60 questions. Pick an option to check it.

Read the notes Subjective questions

0 of 60 answered 0 right 0 wrong , 60 left

  1. Question 1 of 60 opening and closing files Easy

    Which library function is used to open a file in C?

  2. Question 2 of 60 opening and closing files Easy

    What does fopen() return if it fails to open a file?

  3. Question 3 of 60 opening and closing files Easy

    Which mode string opens a file only for reading?

  4. Question 4 of 60 opening and closing files Easy

    Which function is used to close a file in C?

  5. Question 5 of 60 opening and closing files Easy

    What is the correct data type of the pointer used to handle files in C?

  6. Question 6 of 60 opening and closing files Easy

    Which mode opens a file for writing and creates it if it does not exist, erasing any existing content when it does exist?

  7. Question 7 of 60 opening and closing files Easy

    Which mode is used to add data at the end of an existing file without deleting its contents?

  8. Question 8 of 60 text and binary files Easy

    Which character is added to a mode string to open a file in binary mode?

  9. Question 9 of 60 text and binary files Easy

    In which type of file is data stored as human-readable characters?

  10. Question 10 of 60 text and binary files Easy

    Which type of file stores data in the same format as it is held in memory?

  11. Question 11 of 60 reading and writing in files Easy

    Which function writes a single character to a file?

  12. Question 12 of 60 reading and writing in files Easy

    Which function reads a single character from a file?

  13. Question 13 of 60 reading and writing in files Easy

    Which function is used to write formatted output to a file?

  14. Question 14 of 60 reading and writing in files Easy

    Which function reads formatted input from a file?

  15. Question 15 of 60 reading and writing in files Easy

    Which function is used to write a whole string to a file?

  16. Question 16 of 60 reading and writing in files Easy

    Which function reads a line or string from a file?

  17. Question 17 of 60 reading and writing in files Easy

    Which pair of functions is typically used for reading and writing blocks of data in binary files?

  18. Question 18 of 60 reading and writing in files Easy

    What does EOF stand for in C file handling?

  19. Question 19 of 60 categories of files Easy

    Based on how their data is stored, files in C are broadly categorized into which two types?

  20. Question 20 of 60 categories of files Easy

    Which of the following is a valid reason for using files in a C program?

  21. Question 21 of 60 opening and closing files Medium

    What does the fopen() function return if it fails to open the specified file?

  22. Question 22 of 60 opening and closing files Medium

    A program opens a file using fopen("data.txt", "w") when data.txt already exists with content. What happens to the existing content?

  23. Question 23 of 60 opening and closing files Medium

    Why is calling fclose() on a file opened for writing important?

  24. Question 24 of 60 opening and closing files Medium

    Which mode string opens a file for both reading and writing, creating it if it does not exist and truncating it if it does?

  25. Question 25 of 60 text and binary files Medium

    On a Windows system, what is the main effect of opening a file in text mode versus binary mode?

  26. Question 26 of 60 text and binary files Medium

    Why is fwrite() generally preferred over fprintf() for storing a large array of float values?

  27. Question 27 of 60 text and binary files Medium

    A structure written to a binary file with fwrite on one machine may not read correctly on another. What is the most common reason?

  28. Question 28 of 60 categories of files Medium

    Which of the following streams is automatically opened when a C program starts and is associated with error output?

  29. Question 29 of 60 categories of files Medium

    What distinguishes a sequential-access file from a random-access file in C?

  30. Question 30 of 60 reading and writing in files Medium

    Consider the code below. What is written to out.txt?

    C
    FILE *fp = fopen("out.txt", "w");
    fprintf(fp, "%d-%d", 5, 3);
    fclose(fp);

  31. Question 31 of 60 reading and writing in files Medium

    Which function is most appropriate for reading a full line of text (including spaces) from a file into a buffer?

  32. Question 32 of 60 reading and writing in files Medium

    What value does feof(fp) return immediately after a successful read that has NOT yet reached the end of the file?

  33. Question 33 of 60 reading and writing in files Medium

    Given a binary file of 10 int values, which call correctly moves the file position to the 5th integer for reading?

  34. Question 34 of 60 reading and writing in files Medium

    What does fread(buf, 4, 10, fp) return when only 6 complete elements are available before end of file?

  35. Question 35 of 60 reading and writing in files Medium

    Which statement about fputc() and fgetc() is correct?

  36. Question 36 of 60 opening and closing files Medium

    A file is opened in mode "a". Where is data written regardless of any fseek calls before writing?

  37. Question 37 of 60 text and binary files Medium

    Reading an integer stored via fprintf(fp, "%d", 300) requires which function to recover the value 300?

  38. Question 38 of 60 reading and writing in files Medium

    What is the effect of rewind(fp) on an open file?

  39. Question 39 of 60 categories of files Medium

    Which pair of standard streams is buffered and unbuffered respectively by default in most C implementations?

  40. Question 40 of 60 reading and writing in files Medium

    A loop uses while (fscanf(fp, "%d", &x) == 1) to read integers. Why compare against 1?

  41. Question 41 of 60 opening and closing files Hard

    Consider the code:
    c
    FILE *fp = fopen("data.txt", "r");
    if (fp == NULL) return 1;
    fclose(fp);
    fprintf(fp, "hello");

    What is the most accurate description of the fprintf call after fclose?

  42. Question 42 of 60 text and binary files Hard

    On a Windows system, a program writes the single byte 0x0A (LF) to a file opened in text mode "w". What does the file most likely contain on disk?

  43. Question 43 of 60 reading and writing in files Hard

    Given int x = 300; written with fwrite(&x, sizeof(int), 1, fp) on a little-endian machine, which byte sequence is stored (assuming 4-byte int)?

  44. Question 44 of 60 reading and writing in files Hard

    Which statement about fseek(fp, 0, SEEK_END) followed by ftell(fp) on a text-mode file is correct?

  45. Question 45 of 60 opening and closing files Hard

    A file opened with mode "a+" has content ABC. After fread reads nothing (EOF just reached), the program calls fwrite("XY", 1, 2, fp). Where is XY written?

  46. Question 46 of 60 reading and writing in files Hard

    What does feof(fp) return immediately after fopen succeeds but before any read operation?

  47. Question 47 of 60 text and binary files Hard

    Why can reading a struct with fread that was written by fwrite on a different platform produce incorrect values, even with identical source code?

  48. Question 48 of 60 reading and writing in files Hard

    In the loop while ((c = fgetc(fp)) != EOF) { ... }, why must c be declared as int rather than char?

  49. Question 49 of 60 opening and closing files Hard

    A program opens 2000 files in a loop without closing them and eventually fopen returns NULL. What is the most likely cause?

  50. Question 50 of 60 reading and writing in files Hard

    After a successful fwrite to a stream opened "r+", a program immediately calls fread without any intervening call. What does the C standard require?

  51. Question 51 of 60 text and binary files Hard

    A file created in binary mode "wb" stores the two bytes 0x0D 0x0A. It is later opened "rt" (text) on Windows and read with fgetc. How many characters does the program typically read before EOF?

  52. Question 52 of 60 reading and writing in files Hard

    What is the return value of fwrite(buf, 4, 5, fp) if it successfully writes 3 complete elements and part of a 4th before the disk fills?

  53. Question 53 of 60 categories of files Hard

    In C's stream model, which statement best distinguishes a text stream from a binary stream?

  54. Question 54 of 60 opening and closing files Hard

    What happens when fopen("log.txt", "w") is called on an existing non-empty file?

  55. Question 55 of 60 reading and writing in files Hard

    Given the input line 42abc in a file, what does fscanf(fp, "%d", &n) do to the stream and n?

  56. Question 56 of 60 reading and writing in files Hard

    Why might data written with fprintf fail to appear in a file even though the program printed no errors, if the program terminates via abort()?

  57. Question 57 of 60 text and binary files Hard

    A program writes an int array using fwrite in mode "w" (text) instead of "wb" on Windows. What is the primary risk?

  58. Question 58 of 60 reading and writing in files Hard

    Using fgets(buf, 5, fp) on a line Hello\n, how many characters are stored and what is buf?

  59. Question 59 of 60 opening and closing files Hard

    What does freopen("out.txt", "w", stdout) accomplish?

  60. Question 60 of 60 reading and writing in files Hard

    A record file stores fixed-size 20-byte records. To seek directly to the 5th record (1-based) for reading with fread, which call is correct?

That's unit 6

Answer a few questions and your score shows up here.