Programming Exam 2 Quiz Questions

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

Assuming that t is an array and tPtr is a pointer to that array, what expression refers to the address of element 3? *(tPtr + 3) tPtr[3] &t[3] *(t + 3)

&t[3]

If bPtr is assigned b (the name of an array), then array element b[3] can alternatively be referenced with the pointer expression __________. bPtr + 3 b[bPtr + 3] *b [bPtr + 3] *(bPtr + 3)

*(bPtr + 3)

What is the output of the following statement?printf( "%s", strspn( "Cows like to moo.", "Ceiklosw " ); Nothing. 10 8 e

10

Evaluate (00001000 & 11000101) ^ (11110000) 00111101 11000000 00111101 11110000

11110000

The statement printf( "%*.*f", 7, 2, 98.736 ); uses _______ for the precision, __________ for the field width and outputs the value 98.74 __________. 7, 2, left justified 2, 7, left justified 2, 7, right justified 7, 2, right justified

2, 7, right justified

Given that k is an integer array starting at location 2000, kPtr is a pointer to k, and each integer is stored in 4 bytes of memory, what location does kPtr + 3 point to? 2003 2006 2012 2024

2012

Values printed with the conversion specifiers e, E and f are output with __________ digits of precision to the right of the decimal point by default. 0 1 5 6

6

The number 4 typically takes up _________ bit(s) when stored as a character on most of today's computers. 1 2 3 8

8

With the %g conversion specifier, the value 0.0000875 prints as 8.75e-05 87.5e-06 0.875e-04 0 (because of truncation)

8.75e-05

Which statement is false? A pointer can always be assigned to another pointer of the same type. A cast operator must always be used to convert the pointer on the right of an assignment to the pointer type on the left of the assignment. Variables of all pointer types can be assigned a pointer to void. A pointer to void can be assigned a pointer of any type.

A cast operator must always be used to convert the pointer on the right of an assignment to the pointer type on the left of the assignment

Which statement is false? Structures are derived data types. Each structure definition must end with a semicolon. A structure can contain an instance of itself. Structures may not be compared using operators == and !=.

A structure can contain an instance of itself.

Which of the following is true? Any bit "ANDed" with 0 yields 0. Any bit "ANDed" with 1 yields 1. Any bit "ANDed" with 0 yields 1. Any bit "ANDed" with 1 yields 0.

Any bit "ANDed" with 0 yields 0.

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

C11's new exclusive mode allows fopen to open a file only if it does not already exist.

Which of these is not a common programming error? Referring to memory that has been freed. Freeing memory (with free) that was not dynamically allocated. Assuming that the size of a structure is simply the sum of the sizes of its members. Calling malloc in a statement without using sizeof.

Calling malloc in a statement without using sizeof.

Which of the following is not a valid operation on a structure? Assigning structure variables to structure variables of the same type. Taking the address of a structure variable. Using the sizeof operator to determine the size of a structure variable. Comparing structures of the same type with relational operators.

Comparing structures of the same type with relational operators.

Which of the following is always a syntax error? Not using srand in every program that uses rand. Not using rand in every program that uses srand. Not using const when passing an array. Forgetting to include the array subscript when referring to individual structures in an array of structures.

Forgetting to include the array subscript when referring to individual structures in an array of structures.

Which statement is true? Function fprintf is equivalent to printf. 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. 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. Function fprintf is equivalent to printf except that fprintf also disables the file end-of-file indicator.

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.

Which of the following statements is false? The primary functions used to manipulate a stack are push and pop. Function pop removes a node from the bottom of the stack. Function push creates a new node and places it on top of the stack. A stack can be implemented as a constrained version of a linked list by allowing insertions and deletions only at one end of the linked list.

Function pop removes a node from the bottom of the stack.

Which statement is false? The notations int *array and int array[] are interchangeable. Function prototypes may not be placed inside functions. Good advice: To encourage software reusability, when passing an array, also pass the size of the array. Global variable violate the principle of least privilege.

Global variable violate the principle of least privilege

Which of the following is false? Arrays can be maintained in sorted order. Linked lists can be maintained in sorted order. Insertion and deletion in a sorted array (while maintaining sorted order) is efficient. Once the insertion point or the node to be deleted has been located, insertion or deletion in a sorted linked list (while maintaining sorted order) is efficient.

Insertion and deletion in a sorted array (while maintaining sorted order) is efficient.

Which statement about the algorithm we presented in Section 7.10 of the text for shuffling a deck of cards is true? It's guaranteed to terminate. It could execute indefinitely. It's efficient. It uses a one-dimensional array of 52 cards.

It could execute indefinitely

Which statement about the algorithm we presented in Section 7.10 of the text for shuffling a deck of cards is true? It's guaranteed to terminate. It could execute indefinitely. It's efficient. It uses a one-dimensional array of 52 cards.

It could execute indefinitely.

Which statement about the parameter definition int (*compare)(int, int) is false? It defines a parameter that is a pointer to a function that receives two integer arguments and returns a pointer to an integer as a result. Parentheses are needed around *compare because * has a lower precedence than the parentheses enclosing the function parameters. Without the parentheses it would have defined a function that receives two integers and returns a pointer to an integer. The corresponding parameter in the function prototype would ordinarily be int (*)(int, int)

It defines a parameter that is a pointer to a function that receives two integer arguments and returns a pointer to an integer as a result

What is the significance of the 1 in the following statement? fwrite(&number, sizeof(int), 1, fPtr); It specifies that the file is to be opened for updating. It specifies the number of elements in the array that should be written to disk. It specifies the byte size of the element being written to disk none of these

It specifies the number of elements in the array that should be written to disk.

Which statement is false? The operand of the address operator must be a variable. The address operator cannot be applied to constants or to expressions. The address operator can be applied to variables defined with the storage class register. The address operator can be applied to variables defined with the storage class static.

The address operator can be applied to variables defined with the storage class register

Which statement is false? The operand of the address operator must be a variable. The address operator cannot be applied to constants or to expressions. The address operator can be applied to variables defined with the storage class register. The address operator can be applied to variables defined with the storage class static.

The address operator can be applied to variables defined with the storage class register.

Which statement is false? Function strcpy copies its first argument into its second argu-ment. Function strncpy does not necessarily copy the terminating null character of its second argument. A common error is not appending a terminating null character to the first argument of a strncpy when the third argument is less than or equal to the length of the string in the second argument. The first character of the second argument of strcat replaces the null character that terminates the string in the first argument.

The first character of the second argument of strcat replaces the null character that terminates the string in the first argument.

Which statement is true? The members of a union can be of any type. The members of a union must all be of the same type. A union may not be assigned to another union of the same type. Unions may be compared to other unions of the same type.

The members of a union can be of any type.

Which of the following statements is false? The programmer must know the specifics of the FILE structure to use files. The FILE structure for a file leads indirectly to the operating system's file control block (FCB) for a file. If a file does not exist and is opened for writing fopen creates the file. A C program administers each file with a separate FILE structure.

The programmer must know the specifics of the FILE structure to use files.

Which statement about function memcpy is false? It copies a specified number of characters from the object pointed to by its second argument into the object pointed to by its first argument. It can receive a pointer to any type of object. The result of this function is defined even if the two objects overlap in memory. Function memmove correctly handles the situation for which mem-cpy most notably fails.

The result of this function is defined even if the two objects overlap in memory.

Which statement is false? In C, a string is essentially a pointer to its first character. Arrays may contain pointers. Each entry in an array of strings is actually a pointer to the first character of a string. The size of an array of strings is the sum of the lengths of the strings.

The size of an array of strings is the sum of the lengths of the strings

Which statement is false? The unary * operator is called the indirection operator or the dereferencing operator. The operand of the unary * operator must be a pointer. The unary * operator returns the value of its operand. Placing a * operator before a pointer dereferences the pointer.

The unary * operator returns the value of its operand

Which statement about pointers is false? A pointer with the value NULL points to nothing. NULL is a symbolic constant defined in the <stdio.h> header file. Initializing a pointer to 0 is equivalent to initializing a pointer to NULL, but NULL is preferred. The values 0 and 1 are the only values that can be assigned directly to a pointer variable.

The values 0 and 1 are the only values that can be assigned directly to a pointer variable

Which statement about pointers is false? A pointer with the value NULL points to nothing. NULL is a symbolic constant defined in the <stdio.h> header file. Initializing a pointer to 0 is equivalent to initializing a pointer to NULL, but NULL is preferred. The values 0 and 1 are the only values that can be assigned directly to a pointer variable.

The values 0 and 1 are the only values that can be assigned directly to a pointer variable.

Which is correct? Use the size operator to determine the size of a structure. Use the struct size operator to determine the size of a structure. Use the sizeof operator to determine the size of a structure. Determine the size of a structure manually by carefully adding up the sizes of the members.

Use the sizeof operator to determine the size of a structure.

Which of the following statements is false? Pointers should not be left uninitialized. When you use free to deallocate dynamically allocated memory, the pointer passed to free is set to NULL. Undefined behavior occurs when you attempt to use free to deallocate dynamic memory that was already deallocated Function malloc returns NULL if it's unable to allocate the requested memory.

When you use free to deallocate dynamically allocated memory, the pointer passed to free is set to NULL.

Which integer conversion specifier would display the hexadecimal digit A? h H x X

X

When the __________ of a variable is passed to a function, the indi-rection operator (*) may be used in the function to modify the __________ at that location in the caller's memory. address, address value, address value, value address, value

address, value

Which mode would you use if you wanted to open a file for both reading and writing? r+ w+ a+ all of these

all of these

A node can only be inserted __________ in a binary search tree. as the root node as a leaf node as a parent node as an ancestor node

as a leaf node

Which operator sets the bits in the result to 1 if at least one of the corresponding bits in the two operands is 1? bitwise AND bitwise inclusive OR bitwise exclusive OR bitwise complement

bitwise inclusive OR

A field width ________ be included in the format control string of the scanf statement. can cannot must none of these

can

Conversion specifier c requires a(n) __________ argument. pointer to char char integer ASCII numeric

char

Creating a new name with typedef __________. creates a new type creates a new type name creates a new variable name creates a new variable

creates a new type name

A floating-point value always contains a __________. decimal point comma plus sign e or E

decimal point

Function feof __________. forces an end-of-file condition determines whether the end-of-file indicator is set for a file sets the end-of-file indicator for a file flushes the contents of the file from the current position to the end

determines whether the end-of-file indicator is set for a file

A non-pointer variable name __________ references a value and a pointer variable name __________ references a value. directly, directly directly, indirectly indirectly, directly indirectly, indirectly

directly, indirectly

Function __________ reads one character from a file. fgetcharacter fgetc fgetchar fgetbyte

fgetc

Queues are linear data structures with the property that queue nodes are inserted only at the tail of the queue and removed only from the head of the queue. For this reason, queues are referred to as __________ data structures. first-in, first-out first-in, last-out last-in, first-out first-come, first-served

first-in, first-out

Which of the following is a function that reads a specified number of bytes from a file into memory? fseek fwrite fread fopen

fread

The isxdigit (is hex digit) function would return false on a A 2 g

g

Referencing a value through a pointer is called __________. interdiction indirection intermediation redirection

indirection

If there are fewer __________ in the list than members in the structure, the remaining members are automatically initialized to 0 or NULL. quantifiers initializers numerators variables

initializers

The standard __________ stream enables a program to read data from the keyboard. read keyboard dialog input

input

When a compiler encounters a function parameter for a sin-gle-subscripted array of the form int a[], it converts the parameter to int a int &a int * a int * const a

int * a

The functions of the character-handling library typically manipu-late characters as ___________. ints. floats. longs. bits.

ints

(*max)(num1, num2, num3); is the header for function max is a call to function max is the prototype for function max is part of a definition of a pointer to the function max

is a call to function max

Which character-handling library function returns a true value if its argument is a letter and 0 otherwise? isalphanumeric isalphabetic isalpha isletter

isalpha

Which character handling library function returns true if its argument is a printing character? ispchar isprintablechar isprint isprintchar

isprint

What does the \\ do when used in a format control string? It outputs the backslash character It delimits comments both a and b none of these

it outputs the backslash character

Which is not a popular application of stacks? enabling called functions to return to their callers supporting recursive function calls containing the space created for automatic variables maintaining waiting lines

maintaining waiting lines

Pointers are variables that contain __________ as their values. strings flowlines memory addresses directions

memory addresses

Conversion specifiers g or G always print __________. no trailing zeros one trailing zero as many trailing zeros as are in the number itself a default of six trailing zeros

no trailing zeros

The highest level of data access is granted by a non-constant pointer to non-constant data. non-constant pointer to constant data. constant pointer to non-constant data. constant pointer to constant data.

non-constant pointer to non-constant data

A function that prints a string should have a parameter that's a nonconstant pointer to nonconstant data. nonconstant pointer to constant data. constant pointer to nonconstant data. constant pointer to constant data.

nonconstant pointer to constant data

What would be the output of the following statements? char* value = "hello";printf( "%c", value ); h hello value none of these

none of these

Arrays are always passed call-by-reference. passed call-by-reference unless inside a structure. always passed call-by-value. passed call-by-value unless inside a structure.

passed call-by-reference unless inside a structure.

A self-referential structure contains a ________ member that points to ________. integer, a structure of the same structure type pointer, an integer integer, an integer pointer, a structure of the same structure type

pointer, a structure of the same structure type

Functions such as isEmpty and isFull that test a condition and return a value that can be interpreted as true or false, are called __________ functions. imperative declarative predicate conditional

predicate

Which is not a part of a format control string? conversion specifiers flags field widths printf

printf

Which of the following is the correct way to output the value of 4 left justified? printf( "%i", 4 ); printf( "%-i", 4 ); printf( "4%i", 4 ); printf( "4-%i", 4 );

printf( "%-i", 4 );

Which of the following is an argument of the fseek function that can have the values SEEK_SET,SEEK_CUR or SEEK_END? stream offset whence none of these

whence

memcmp would return ___________ for the callmemcmp("Hi, how are you?", "Hi, how are things?", 6); -1 a negative number. zero. a positive number.

zero

What does the statement typedef struct card Card; do? Defines card as a synonym for Card. Defines Card as a synonym for card. Defines Card as a synonym for struct card. Defines Card as a synonym for typedef struct card.

Defines Card as a synonym for struct card.

Which statement is generally false? Initializing pointers is optional. Dereferencing an uninitialized pointer could lead to a fatal execu-tion time error. Deferencing an uninitialized pointer could accidentally modify im-portant data. Derefencing an uninitialized pointer causes a syntax error.

Derefencing an uninitialized pointer causes a syntax error

__________ is not an advantage of linked lists when compared to arrays. Dynamic memory allocation Efficient insertion and deletion Direct access to any list element Efficient use of memory

Direct access to any list element

Which of the following is true? Unions may be compared using the == operator. The address operator (&) cannot be used to take the address of a union. Unions may only contain two data types. Only one union member, and thus one data type, can be referenced at a time

Only one union member, and thus one data type, can be referenced at a time

__________ represent waiting lines; insertions are made at the back (also called the tail) and deletions are made from the front (also called the head) of a __________. Linked lists, linked list Queues, queue Stacks, stack Binary trees, binary tree

Queues, queue

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

Randomly accessed files cannot be accessed directly without searching through other records

The steps for an in-order traversal of a binary search tree include each of the following except _________. Traverse the left subtree in-order. Process the value in the root node. Skip over duplicate values. Traverse the right subtree in-order,

Skip over duplicate values.

__________ are important in compilers and operating systems—insertions and deletions are made only at one end of a __________—its top. Linked lists, linked list Queues, queue Stacks, stack Binary trees, binary tree

Stacks, stack

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

receives as an argument a file pointer for the file from which the data is read.

Pointers cannot be used to find the address of a variable in memory. reference values directly. simulate call-by-reference. manipulate dynamic data structures.

reference values directly

Which is not an input formatting capability of scanf? inputting all types of data inputting specific characters from an input stream skipping specific characters in the input stream replacing specific characters in the input stream

replacing specific characters in the input stream

sizeof is a binary operator returns the total number of elements in an array usually returns a double returns the total number of bytes in an array

returns the total number of bytes in an array

Which of the following is a function that causes a program's file position pointer to be repositioned to the beginning of the file? rescan rewind return none of these

rewind

Which is not a capability of the string-handling library? tokenizing strings comparing strings searching strings inputting strings

searching strings

A structure containing a member that's a pointer to the same structure type is referred to as a __________ structure. self-referential self-describing self-recursive self- elemental

self-referential

Which statement is true? sprintf takes its input from a character array. sprintf prints its output in string format on the screen. sprintf stores its output in a character array. sprintf is a secure version of printf.

sprintf prints its output in string format on the screen.

Suppose you have a list of names sorted in alphabetical order, already stored in one of the data types below. The easiest way to print the names in reverse alphabetical order would be to use a binary search tree stack queue circular, singly linked list

stack

The general utilities library is stdutil stdlibrary stdutility stdlib

stdlib

Which of the following does not necessarily append the null character to its result? strcpy strncpy strcat strncat

strncpy

Which function would be the most useful for determining if a certain word is contained in a string representing a sentence? strcspn strchr strstr strrchr

strstr

The ________ accesses a structure member via the structure variable name. structure member operator structure pointer operator structure arrow operator none of these

structure member operator

An algorithm that could execute for an unknown amount of time because it depends on random numbers to exit a function may have a redundancy. get caught in an infinite loop. suffer from indefinite postponement. issue a compiler error.

suffer from indefinite postponement.

Function fgets appends a __________ to its array target in memory. leading null character leading end-of-file character terminating null character terminating end-of-file character

terminating null character

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

the operating system normally will close the file when program execution terminates

Which character-handling library function converts lowercase letters to uppercase letters? lowertoupper isupper touppercase toupper

toupper


Kaugnay na mga set ng pag-aaral

Financial Management of the Firm

View Set

Information Systems Security - C845

View Set

AP Chemistry Semester Test Study Guide

View Set

Chapter 35: Hypothalamic and Pituitary Agents

View Set

Week 7 Mastering Assignment CHEM1252

View Set

Ch. 11 - Input Demand: Capital Market and the Investment Decision

View Set