COP2220: Exam 4
Given: int arry[5] = {1,2,3,4,5}; what is the value at arry[3]? -None of the above -4 -5 -3
4
The worst case scenario for the performance of an algorithm is called ____________________. -Big deal -Big Theta -Big O -Big Bopper
Big O
Strings are never terminated with a special character called the null character, '\0'.
False
The output function puts() can send a string to any data stream including user defined streams.
False
The realloc(release allocation) function is used to release memory when it is no longer needed.
False
The width specifier shown below is correct? fscanf(sPtr, ""9%s", ary);
False
This is a valid/correct use of a pointer? int ary[10] = {1,2,3,4,5,6,7,8,9}; int* aPtr = &ary[13];
False
When an array is declared and defined, the array is automatically initialized to all zeros or null.
False
When storing an item in an array the address operator must always be used.
False
In C when the double quote operator is used to denote a string, C automatically adds a ________ to the end of the string. -NULL character -EOF -'\n' -empty space
NULL character
Given: int arry[5] = {1,2,3,4,5}; what is the value at arry[5]? -1 -There is no index 5 -5 -4
There is no index 5
the gets() function is considered dangerous because ______________. -There is no way to limit the size of the string read in. -the string has no where to go -it is not considered dangerous, that is fgets() -gets() is not a function
There is no way to limit the size of the string read in.
Which of the following is false about releasing memory? -To ensure that it is released, allocated memory should be freed before the program ends. -It is an error to dereference a pointer to allocated memory after the memory has been released. -Memory should be freed as soon as it is no longer needed. -It is an error to free memory using free();
To ensure that it is released, allocated memory should be freed before the program ends.
A string is stored as a sequence of characters in memory.
True
A string literal surrounds a character sequence with double quotes
True
An array can be partially initialized.
True
Dynamically allocated memory can only be referenced through pointers.
True
Given a pointer, aPtr, aPtr + n is a pointer to the value or element n elements away.
True
String output functions have no mechanism with which to reformat the data that is output.
True
The elements in an array are all the same data type.
True
There is no string data type in C.
True
When using the scanning functions to store a data element in an array the address operator must be used.
True
Which of the following is not a memory function in C? -alloc() -calloc() -malloc() -free()
alloc()
The ____________ operator is all that is needed to store a value in an array provided the data type is correct and the index is valid. -address -assignment -semi colon -redirection
assignment
One of the limitations of an array is that they ________________________. -cant dynamically increase their size at runtime. -they use indexes to locate elements -they are like a vector -they contain data of the same type
cant dynamically increase their size at runtime.
A string is a sequence of ___________ which are often treated as a single dimensional array of ________. -characters, characters -ASCII, Data -data, integers -bytes, bits
characters, characters
Static memory allocation requires that the ____________ and definition of memory be specified at compile time. -declaration -initialization -naming -type
declaration
A __________ is a sequence of one or more characters used to determine when to stop processing something. -delimiter -EOF -character set -edit set
delimiter
With a sequential search, in the worst case __________ element in the data structure must be visited. -every -all but the last -none -some
every
The binary search is ____________ than a sequential search because its rate of growth in Big O notation is logarithmic where sequential search growth is linear. -faster -about the same -negligible -slower
faster
The string length function strlen() is useful when using the _____ function because you can specify the size to read in.
fgets()
There are two types of arrays. They are ___________ and ____________ arrays. -multi dimensional and single -fixed length and variable length -integer and character -long and short
fixed length and variable length
A ____________ can be initialized at declaration and definition time. -fixed length array -variable length array -integer array -character array
fixed length array
Dynamic memory gets memory from the ________ a block of memory, usually considered "slow" memory. -heap -stack -global -RAM
heap
The location of an element in an array is located using the _____________. -number -address -index -sub script
index
The malloc() function is different than the calloc(0 function in that _____________________. -malloc() does not initialize the allocated memory. -calloc() does not initialize the allocated memory. -malloc() returns a NULL pointer and calloc() does not. -malloc() is not as fast as calloc()
malloc() does not initialize the allocated memory.
You should always use a width specifier when scanning strings in to avoid __________. -overflowing your array -its just a good idea -to assist the processing -so you know your length
overflowing your array
Dynamic memory is allocated during ____________. -runtime -compiling -processing -file input and output
runtime
The program almost always runs in _______ memory which is considered faster access memory. -stack -heap -CPU -RAM
stack
The following code will do what? int arry[5] = {1,2,3,4,5,6}; -create an array and initialize it -it will work fine -It wont compile -the code will write to memory out of bounds and may cause unpredictable behavior.
the code will write to memory out of bounds and may cause unpredictable behavior.
The name of an array is a pointer to ________________. -the first element in the array -the whole array -a predictable location -type char
the first element in the array
One off the challenges when using the scanning functions scanf() and fscanf() is that if a read stops or fails _________________________. -there is no indication -there is still data in the buffer that needs flushed -you have to do stuff -the data is incorrect.
there is still data in the buffer that needs flushed
When a scanf() function stops scanning string data when it encounters __________ . -EOF -leading white space -segment fault -trailing white space
trailing white space
The sequential search is the ____________ way to search for a data element when there are more than a 50 data elements. -best average -only -fastest -worst/slowest
worst/slowest