11.1 Introduction
11.1 ________ are used for permanent retention of large amounts of data.
(a) Structures
(b) Arrays
(c) Records
(d) Files
ANS: (d)
11.2 Which of the following is false?
a) Storage of data in memory variables is temporary; all such data is lost when a program terminates.
b) Computers store files on primary storage devices, typically disk storage devices.
c) Files are used for permanent retention of data (typically large amounts of data).
d) Storage of data in memory arrays is temporary; all such data is lost when a program terminates.
ANS: (b)
11.2 Files and Streams
11.3 Which of the following is not a stream associated with C files?
(a) stdin
(b) stdout
(c) stdchar
(d) stderr
ANS: (c)
11.4 Which of the following is not part of the FILE structure specified in <stdio.h>?
(a) file descriptor
(b) open file table
(c) read/write methods
(d) file control block
ANS: (c)
11.5 C views each file simply as a sequential stream of __________.
a) bits
b) bytes
c) fields
d) records
ANS: (b)
11.6 Which of the following is not automatically opened when a C program begins?
a) standard error
b) standard output
c) standard dialog
d) standard input
ANS: (c)
11.7 __________ provide communication channels between files and programs.
a) Streams
b) Records
c) File descriptors
d) File control blocks (FCBs)
ANS: (a)
11.8 The standard __________ stream enables a program to read data from the keyboard.
a) read
b) keyboard
c) dialog
d) input
ANS: (d)
11.9 Function __________ reads one character from a file.
a) fgetcharacter
b) fgetc
c) fgetchar
d) fgetbyte
ANS: (b)
11.10 Function fputs writes a __________ to a file.
a) character
b) stream
c) line
d) standard output
ANS: (c)
11.3 Creating a Sequential-Access File
11.11 Which mode would you use if you wanted to open a file for both reading and writing?
(a) r+
(b) w+
(c) a+
(d) all of these
ANS: (d)
11.12 If an error occurs while opening a file in any mode, function fopen returns ________.
(a) true
(b) NULL
(c) false
(d) -1
ANS: (b)
11.13 Which statement is true?
a) C imposes no structure on a file.
b) C imposes record structure on a file.
c) C imposes sequential access on a file.
d) C imposes hierarchical access on a file.
ANS: (a)
11.14 Which statement is false?
a) The programmer must provide any file structure to meet the requirements of each particular application.
b) A programmer can impose a record structure on a file.
c) Records must be written to a C file in order by record key.
d) The notion of a record of a file does not exist in C.
ANS: (c)
11.15 Which of the following statements is false?
a) The programmer must know the specifics of the FILE structure to use files.
b) The FILE structure for a file leads indirectly to the operating system’s file control block (FCB) for a file.
c) If a file does not exist and is opened for writing fopen creates the file.
d) A C program administers each file with a separate FILE structure.
ANS: (a)
11.16 Before a file can be accessed it must first be
a) copied
b) read
c) written
d) opened
ANS: (d)
11.17 If an existing file is opened for writing __________.
a) the contents of the file are preserved
b) the contents of the file are discarded and an error code is returned
c) the contents of the file are discarded without warning
d) the newly written data is appended to the end of the file
ANS: (c)
11.18 Function feof __________.
a) forces an end-of-file condition
b) determines whether the end-of-file indicator is set for a file
c) sets the end-of-file indicator for a file
d) flushes the contents of the file from the current position to the end
ANS: (b)
11.19 Which statement is true?
a) Function fprintf is equivalent to printf.
b) Function fprintf is equivalent to printf except that fprintf also receives as an argument a file pointer for the file to which the data will be written.
c) Function fprintf is equivalent to printf except that fprintf also receives as an argument a file control block for the file to which the data will be written.
d) Function fprintf is equivalent to printf except that fprintf also disables the file end-of-file indicator.
ANS: (b)
Reviews
There are no reviews yet.