题目
COMP10002_2025_SM2 Supplementary or Special Exam: Foundations of Algorithms (COMP10002_2025_SM2)- Requires Respondus LockDown Browser
单项选择题
Consider the following C code sequence: while (fread(&thing, sizeof(data_t), 1, fp) == 1) { // process item that was read ... } If this code sequence and function call appears in a program, it can be reasonably expected:
选项
A.That thing is an object of type data_t, that fp is a pointer to a FILE object that is open for reading, and that the corresponding file contains exactly one object of type data_t
B.That thing is an object of type data_t, that fp is a pointer to a FILE object that is open for writing, and that thing is to to be written to the corresponding file
C.That thing is an object of type data_t, that fp is a pointer to a FILE object that is open for reading, and that the corresponding file contains zero or more objects of type data_t
D.That thing is an object of type data_t, that fp is a pointer to a FILE object that is open for reading, and that the corresponding file contains one or more objects of type data_t
E.That data_t is an object of type thing, that fp is a pointer to a FILE object that is open for reading, and that the corresponding file contains exactly one object of type data_t
查看解析
标准答案
Please login to view
思路分析
To begin, consider what the code is doing: it repeatedly calls fread to read one item of size sizeof(data_t) from the file pointer fp into the object thing, and it loops as long as exactly one item was read. This implies that fp must be a FILE* opened for reading, and that the file contains zero or more objects of type data_t; the loop will terminate when fread returns a value other than 1, which happens at end-of-file or on an error.
Option 1: 'That thing is an object of type data_t, that fp is a pointer......Login to view full explanation登录即可查看完整答案
我们收录了全球超50000道考试原题与详细解析,现在登录,立即获得答案。
类似问题
Which statement below can be used to read data from a file one character at a time?
In the code snippet below, if the file contains the following words: apple, pear, and banana stored one per line, what would be the output? infile = open("input.txt", "r") for word in infile : word = word.rstrip() print(word)
What is returned when the readline method reaches the end of the file?
The following code segment is supposed to read all of the lines from test.txt and save them in copy.txt. infile = open("test.txt", "r") outfile = open("copy.txt", "w") line = infile.readline() ____________________ outfile.write(line) line = infile.readline() infile.close() outfile.close() Which line of code should be placed in the blank to achieve this goal?
更多留学生实用工具
希望你的学习变得更简单
加入我们,立即解锁 海量真题 与 独家解析,让复习快人一步!