Register Now

Login

Lost Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Login

Register Now

Welcome to All Test Answers

Chapter 11 – C How to Program 6e Multiple Choice Test Bank


 

Download  file with the answers

Not a member!
Create a FREE account here to get access and download this file with answers


11.1 Introduction

11.1 ________ are used for permanent retention of large amounts of data.
(a) Structures
(b) Arrays
(c) Records
(d) Files

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.

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

11.4 Which of the following is not part of the FILE structure specified in ?
(a) file descriptor
(b) open file table
(c) read/write methods
(d) file control block

11.5 C views each file simply as a sequential stream of __________.
a) bits
b) bytes
c) fields
d) records

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

11.7 __________ provide communication channels between files and programs.
a) Streams
b) Records
c) File descriptors
d) File control blocks (FCBs)

11.8 The standard __________ stream enables a program to read data from the keyboard.
a) read
b) keyboard
c) dialog
d) input

11.9 Function __________ reads one character from a file.
a) fgetcharacter
b) fgetc
c) fgetchar
d) fgetbyte

11.10 Function fputs writes a __________ to a file.
a) character
b) stream
c) line
d) standard output

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+

11.12 If an error occurs while opening a file in any mode, function fopen returns ________.
(a) true
(b) NULL
(c) false
(d) -1

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.

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.

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.

11.16 Before a file can be accessed it must first be
a) copied
b) read
c) written
d) opened

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

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

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.

11.20 If a file is not closed explicitly by a program __________.
a) the operating system normally will close the file when program execution terminates
b) the file will be left open when the program terminates, creating a possible security breach
c) the operating system will query the user to determine if he or she wishes to close the file when the program terminates
d) the operating system will not allow the owner of that program to run any other programs

11.21 Which statement is false?
a) Each file used in a program must have a unique name and will have a different file pointer returned by fopen.
b) All subsequent file processing functions after the file is opened must refer to the file with the appropriate file control block.
c) To create a file use file open mode “w”.
d) To add records to an existing file, pen the file for appending (“a”).

11.22 If an error occurs while opening a file in any mode, fopen __________.
a) causes program termination
b) returns NULL
c) issues the message “can’t open file”
d) diagnoses the error, waits five minutes and retries

11.23 Which statement is true?
a) fopen returns a FILE structure.
b) fopen returns a pointer to a FILE structure.
c) fopen returns a file control block (FCB).
d) fopen returns a pointer to a file control block (FCB).

11.4 Reading Data from a Sequential-Access File

11.24 Function fscanf takes an argument of type ________.
(a) FILE pointer
(b) cfPtr
(c) char
(d) int

11.25 Which of the following is a function that causes a program’s file position pointer to be repositioned to the beginning of the file?
(a) rescan
(b) rewind
(c) return
(d) none of these

11.26 Function fscanf is equivalent to function scanf, except that fscanf
a) can have only a single argument.
b) can read only from standard streams.
c) can read only from open streams.
d) receives as an argument a file pointer for the file from which the data is read.

11.27 The rewind statement causes __________.
a) the disk to stop spinning, then spin in reverse until it repositions to the beginning of the file.
b) the contents of the file to be erased.
c) a program’s file position pointer to be repositioned to the beginning of the file (i.e., byte 0).
d) a file to be closed and then re-opened.

11.28 Which statement is true?
a) The file position pointer is a pointer to a FILE structure.
b) The file position pointer is a pointer to an FCB.
c) The file position pointer is not really a pointer.
d) The file position pointer specifies the file reset.

11.5 Random-Access Files

11.29 Individual records of a randomly accessed file are normally ________.
(a) fixed in length
(b) not fixed in length
(c) sorted by record key
(d) read using the fopen function

11.30 Which of the following is false?
(a) Data can be inserted in a randomly accessed file without destroying other data in the file.
(b) There is more than one way to implement randomly accessed files.
(c) Randomly accessed files cannot be accessed directly without searching through other records.
(d) Data stored previously can be updated or deleted without rewriting the entire file.

11.31 Which statement is false?
a) Randomly accessed files are popular in transaction processing systems.
b) Data stored previously in a randomly accessed file can be updated or deleted without rewriting the entire file.
c) Records of a randomly accessed file are normally fixed in length (i.e., all the record in the file are the same length).
d) A record of a randomly accessed file is normally located by searching the portion of that file which precedes that record.

11.6 Creating a Random-Access File

11.32 What is the significance of the 1 in the following statement?

fwrite( &number, sizeof( int ), 1, fPtr );

(a) It specifies that the file is to be opened for updating.
(b) It specifies the number of elements in the array that should be written to disk.
(c) It specifies the byte size of the element being written to disk
(d) none of these

11.33 Function fwrite __________.
a) is equivalent to function fprintf
b) transfers a specified number of bytes beginning at a specified location in memory to a location in a file indicated by the file position pointer
c) transfers a specified number of bytes beginning at a specified location in memory to a location in a file indicated by one of its arguments
d) is equivalent to function fprintf, except that fwrite can only write to standard streams

11.34 fread and fwrite
a) can not read and write arrays of data
b) process all their data in human readable format
c) process all their data in the same format used by fscanf and fprintf, respectively
d) process all their data in “raw data” format

11.35 Which statement is true?
a) Random access file-processing programs typically read and write one field at a time.
b) Random access file-processing programs typically read and write one struct at a time.
c) The sizeof operator is a run-time unary operator that returns the size in bytes of its operand.
d) The expression sizeof( int ) always returns 4.

11.36 sizeof
a) is a compile-time function
b) is a compile-time unary operator
c) is a run-time unary operator
d) is a run-time function

11.7 Writing Data Randomly to a Random-Access File

11.37 Which of the following is an argument of the fseek function that can have the values SEEK_SET,
SEEK_CUR or SEEK_END?
(a) stream
(b) offset
(c) whence
(d) none of these

11.38 Which statement is true?
a) fseek searches for a record by its record key.
b) fseek sets the file position pointer to a specific byte location in the file.
c) fseek moves the read-write head on the disk to the location on disk that corresponds to a specific location in a file.
d) fseek must immediately follow each call to fread or fwrite.

11.39 The symbolic constant __________ indicates that the file position pointer is to be positioned relative to the beginning of the file by the amount of the offset.
a) SEEK_SET
b) SEEK_BEGIN
c) SEEK_START
d) SEEK_CUR

11.8 Reading Data from a Random-Access File

11.40 Which of the following is a function that reads a specified number of bytes from a file into memory?
(a) fseek
(b) fwrite
(c) fread
(d) fopen

11.41 Which statement is true?
a) fread always reads a record at a time from a file into memory.
b) fread reads a specified number of bytes from a file into memory.
c) Every fread call must include an argument with sizeof.
d) fread reads bytes from a position in the file specified as one of fread’s arguments.

11.9 Case Study: Transaction-Processing Program

11.42 In the statement

fseek ( fPtr, ( account – 1) * sizeof( struct clientData ), SEEK_SET );

why are we adjusting account by –1?

a) Because the account numbers start at 0 and the file starts at position 0.
b) Because the account numbers start at 0 and the file starts at position 1.
c) Because the account numbers start at 1 and the file starts at position 0.
d) Because the account numbers start at 1 and the file starts at position 1.

11.11 Secure C Programming

11.43 Which of the following statements is true?
(a) Files written in binary format are always portable.
(b) C11’s new exclusive mode allows fopen to open a file only if it does not already exist.
(c) All platforms allow you to open an unlimited number of files.
(d) None of the above

About

Leave a reply

Captcha Click on image to update the captcha .

error: Content is protected !!