Intro to C - Part 2

Ace your homework & exams now with Quizwiz!

True

A macro is an operation defined in a #define preprocessor directive. Macros may be defined with or without arguments.

True

An enum defines a set of integer constants represented by identifiers. Values in an enum start with 0, unless specified otherwise, and are incremented by 1.

struct part { int partNumber; char partName[26]; };

Define a structure called part containing int variable partNumber and char array partName with values that may be as long as 25 characters (including the terminating null character).

#define CUBE_VOLUME( x ) ( ( x ) * ( x ) * ( x ) )

Define macro CUBE_VOLUME that computes the volume of a cube. The macro takes one argument.

True

Directives #ifdef and #ifndef are provided as shorthand for #if defined(name) and #if !defined(name).

True

Each open file must have a separately declared pointer of type FILE that is used to refer to the file.

True

Each structure definition must end with a semicolon.

True

Every character in a computer's character set is represented as a pattern of 1s and 0s (called a byte).

True

Function fopen takes as arguments a file name and a file open mode and returns a pointer to the FILE structure for the file opened.

True

Function fscanf is equivalent to function scanf except fscanf receives as an argument a file pointer for the file from which the data is read.

True

Macro assert—defined in the <assert.h> header—tests the value of an expression. If the value of the expression is 0 (false), assert prints an error message and calls function abort to terminate program execution.

reads one character from a file. It receives as an argument a FILE pointer for the file from which a character will be read.

Match the followings: fgets

writes one character to a file. It receives as arguments a character to be written and a pointer for the file to which the character will be written.

Match the followings: fputs

True

Members of structure variables defined outside a function definition are initialized to 0 or NULL if they are not explicitly initialized in the external definition.

True

Members of the same structure type must have unique names.

True

Multiple members of an enumeration can have the same constant value.

True

Only one member of a union can be referenced at a time. It is your responsibility to ensure that the data in a union is referenced with the proper data type.

False

Only white-space characters may appear before a preprocessor directive on a line.

True

Streams provide communication channels between files and programs.

True

Structure definitions do not reserve any space in memory; they create new data types that are used to define variables.

True

Structures can be initialized using initializer lists.

True

Symbolic constants and macros can be discarded by using the #undef preprocessor directive. Directive #undef "undefines" the symbolic constant or macro name.

True

To write several array elements, supply in the call to fwrite a pointer to an array as the first argument and the number of elements to be written as the third argument.

True

•The only valid operations that may be performed on structures are assigning structure variables to variables of the same type, taking the address (&) of a structure variable, accessing the members of a structure variable and using the sizeof operator to determine the size of a structure variable.

True

A record (i.e., a struct) is a group of related fields.

True

A structure cannot contain an instance of itself but may include a pointer to another object of the same type.

True

A structure containing a member that is a pointer to the same structure type is referred to as a self-referential structure. Self-referential structures are used to build linked data structures.

True

A symbolic constant is a name for a constant.

True

A union is declared with keyword union in the same format as a structure. Its members share the same storage space.

True

The #include directive includes a copy of the specified file. If the file name is enclosed in quotes, the preprocessor begins searching in the same directory as the file being compiled for the file to be included. If the file name is enclosed in angle brackets (< and >), the search is performed in an implementation-defined manner.

True

The #line preprocessor directive causes the subsequent source code lines to be renumbered starting with the specified constant integer value.

True

The conditional preprocessor directives evaluate constant integer expressions. Cast expressions, sizeof expressions and enumeration constants cannot be evaluated in preprocessor directives.

True

The data in a sequential file typically cannot be modified without the risk of destroying other data in the file.

True

The keyword typedef provides a mechanism for creating synonyms for previously defined types.

True

All preprocessor directives begin with #.

printf( "%s\n", (*cPtr)->face );

Fix the error in the following snippet: printf( "%s\n", *cPtr->face ); Assume that struct card has been defined containing two pointers to type char, namely face and suit. Also, the variable c has been defined to be of type struct card and the variable cPtr has been defined to be of type pointer to struct card. Variable cPtr has been assigned the address of c.

True

Fixed-length records enable data to be inserted in a random-access file without destroying other data. Data stored previously can also be updated or deleted without rewriting the entire file.

True

Function fclose receives a file pointer as an argument and closes the specified file.

True

Function feof receives a pointer to a FILE and returns a nonzero (true) value when the end-offile indicator has been set; otherwise, the function returns zero.

True

Function fopen returns NULL if it's unable to open a file.

True

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.

True

Function fread transfers a specified number of bytes from the location in the file specified by the file position pointer to an area in memory beginning with a specified address.

True

Function fseek sets the file position pointer for a given file to a specific position in the file. Its second argument indicates the number of bytes to seek and its third argument indicates the location from which to seek. The third argument can have one of three values—SEEK_SET, SEEK_CUR or SEEK_END (all defined in <stdio.h>). SEEK_SET indicates that the seek starts at the beginning of the file; SEEK_CUR indicates that the seek starts at the current location in the file; and SEEK_END indicates that the seek starts at the end of the file.

True

Function fwrite transfers a specified number of bytes beginning at a specified location in memory to a file. The data is written beginning at the file position pointer's location.

True

Function rewind causes a program's file position pointer to be repositioned to the beginning of the file (i.e., byte 0) pointed to its argument.

strcpy( customerRecord.lastName, "Flower");

Given the following structure and variable definitions, struct customer { char lastName[ 15 ]; char firstName[ 15 ]; int customerNumber; struct { char phoneNumber[ 11 ]; char address[ 50 ]; char city[ 15 ]; char state[ 3 ]; char zipCode[ 6 ]; } personal; } customerRecord, *customerPtr; customerPtr = &customerRecord; write an expression that can be used to copy "Flower" to the Member lastName of structure customerRecord.

strcpy( customerRecord.personal.city, "Orlando");

Given the following structure and variable definitions, struct customer { char lastName[ 15 ]; char firstName[ 15 ]; int customerNumber; struct { char phoneNumber[ 11 ]; char address[ 50 ]; char city[ 15 ]; char state[ 3 ]; char zipCode[ 6 ]; } personal; } customerRecord, *customerPtr; customerPtr = &customerRecord; write an expression that can be used to copy "Orlando" to the Member city of member of personal of structure customerRecord.

customerRecord.lastName

Given the following structure and variable definitions, struct customer { char lastName[ 15 ]; char firstName[ 15 ]; int customerNumber; } customerRecord, *customerPtr; customerPtr = &customerRecord; write an expression that can be used to access the Member lastName of structure customerRecord.

False

If enum months { JAN = 1, FEB, MAR, APR, MAY = 4, JUN, JUL, AUG, SEP, OCT, NOV, DEC }, then (JUN+FEB ==6) returns true.

True

If there are fewer initializers in the list than members in the structure, the remaining members are automatically initialized to 0 (or NULL if the member is a pointer).

True

If you wish to determine whether functions like fscanf, fseek and fwrite operate correctly, you can check their return values.

True

Individual records of a random-access file are normally fixed in length and may be accessed directly (and thus quickly) without searching through other records.

True

Opening a file returns a pointer to a FILE structure (defined in <stdio.h>) that contains information used to process the file. This structure includes a file descriptor, i.e., an index into an operating system array called the open file table. Each array element contains a file control block (FCB) that the operating system uses to administer a particular file.

True

Pointers and structures facilitate the formation of more complex data structures such as linked lists, queues, stacks and trees.

False

The #define preprocessor directive is used to create just symbolic constants.

True

The #error directive prints an implementation-dependent message that includes the tokens specified in the directive.

True

The file position pointer is an integer value that specifies the byte location in the file at which the next read or write is to occur. This is sometimes referred to as the file offset. The file position pointer is a member of the FILE structure associated with each file.

True

The members of a union can be of any data type. The number of bytes used to store a union must be at least enough to hold the largest member.

True

The preprocessor executes before a program is compiled.

True

The scope of a symbolic constant or macro is from its definition until it is undefined with #undef or until the end of the file.

True

The standard input stream enables a program to read data from the keyboard, and the standard output stream enables a program to print data on the screen.

True

The structure member operator (.) and the structure pointer operator (->) are used to access structure members.

True

The structure member operator accesses a structure member via the structure variable name.

True

The structure pointer operator accesses a structure member via a pointer to the structure.

True

Three files and their associated streams are automatically opened when program execution begins—the standard input, the standard output and the standard error.

True

To add records to the end of an existing file, open the file for appending ("a").

True

To open a file so that it may be written to and read from, open the file for updating in one of the three update modes—"r+", "w+" or "a+". Mode "r+" opens a file for reading and writing. Mode "w+" creates a file for reading and writing. If the file already exists, it's opened and it's contents are discarded. Mode "a+" opens a file for reading and writing—all writing is done at the end of the file. If the file does not exist, it's created.

#include "common.h"

Write a preprocessor directive to Include the header common.h. The header is found in the same directory as the file being compiled.

#line 3000

Write a preprocessor directive to Renumber the remaining lines in the file beginning with line number 3000.

#if defined( TRUE ) #undef TRUE #define TRUE 1 #endif

Write a preprocessor directive to accomplish the following: If symbolic constant TRUE is defined, undefine it and redefine it as 1. Do not use #ifdef.

#define YES 1

Write a preprocessor directive to define symbolic constant YES to have the value 1.

ofPtr = fopen( "oldmast.dat", "r" );

Write a statement that opens the file "oldmast.dat" for reading and assigns the returned file pointer to ofPtr.

fscanf( ofPtr, "%d%s%f", &accountNum, name, &currentBalance );

Write a statement that reads a record from the file "oldmast.dat". The record consists of integer accountNum, string name and floating-point currentBalance.


Related study sets

Pharmacology Chapter 51 Diuretic Agents

View Set

Chapter 18 - Gastrointestinal and Urologic Emergencies

View Set

Nutrition: Implement and Take Action; Evaluate

View Set

Chapter 17: Investments & business opportunity brokerage

View Set

PassPoint - Medication and IV Administration

View Set

ARCH 3323 - Test 2 - Chapter 4 Short Answer

View Set