1. When a linked list is created, you must know how many nodes the list will con
ID: 3714077 • Letter: 1
Question
1. When a linked list is created, you must know how many nodes the list will contain. A. True B. False
2. ?delete ptr ?deletes the data the pointer is pointing to: A. True B. False
3. ?-> can be used to access variables that are not members of objects. A. True B. False
4. Which ?cctype? function checks if a character is in the alphabet? A. isdigit B. alphanumeric C. AlphabitSoup D. isalpha E. None of the above
5. Given the following code fragment:
struct mystruct{
int x; char y;
};
int main(){
mystruct obj1;
obj1.x = 4;
obj1.y = ‘c’; //ASCII value of c is 99
cout << static_cast<char>(obj1.x + obj1.y) << endl;
return 0;
}
What is the output? A. 7 B. 103 C. g D. The code will not compile E. None of the above
6. The stream class to read from files is ?ifstream. A. True B. False
7. What is the address of the first node within a linked list typically labeled as?
A. tail B. head C. node D. next
8. What is the key downside to using linked lists over arrays?
A. Linked lists are dynamic, meaning they can’t change their size. B. Linked lists aren’t searchable, while arrays are. C. To start searching for an item within a linked list, you must start at the beginning of the list. D. Only certain data types can exist within linked lists, while arrays can be made of integers, doubles, characters, strings, etc.
9. If you have the following code snippet:
int val = 6; int* ptr = &val; cout << ptr;
What is the code’s output? A. The address of ptr B. The address of val C. 6 D. 0
10. If you have the following code snippet:
int val = 6; int* ptr = &val; cout << *ptr;
What is the code’s output?
A. The address of ptr B. The address of val C. 6 D. 0
1080C/CS1 C++ Programming Exam 2 - Spring 2017 - Version A
2
1080C/CS1: C++ Programming Exam 2 - Spring 2017 - Version A
11. In C++, things such as +, *, &&, ->, etc. are known as ___________ .
A. variables B. arguments C. functions D. operators
12. What is the maximum number of values a function can return by using a return statement? A. 0 B. 1 C. 2 D. As many as you want
13. What is the maximum number of values a function can return by using reference variables? A. 0 B. 1 C. 2 D. As many as you want
14. What is ?typically
? considered the worst method of sorting for most cases?
A. Bubble Sort B. Merge Sort C. Quick Sort D. Selection Sort
15. Assume A[0] to A[4] of array A contains: 29, 10, 14, 37, 13. After the first full pass of bubble sort, what is the array contents? A. 10, 14, 29, 13, 37 B. 10, 13, 37, 14, 29 C. 10, 29, 14, 37, 13 D. 10, 37, 13, 14, 29
16. Assume A[0] to A[4] of array A contains: 29, 10, 14, 37, 13. How many comparisons are required to search for the value of 13 using a binary search? A. 1 B. 2 C. 3 D. none of the above
Explanation / Answer
1. False.
A linked list can contain as many items as needed as they dynamically allocate memory for the new nodes. Hence number of nodes needed is not required during creation of the linked list.
2. True.
delete ptr deletes data in the memory dynamically allocated to the ptr in the heap.
3.False.
-> cannot be used to access variables that are not members of objects.
4.D.isalpha
isalpha(c) is a function in C which can be used to check if passed character is an alphabet or not
5.C.g
when we add x to y, we are adding 4 to 'c'. Thus the output character is 'c' + 4 = 'g'
6. A.True
ifstream is the stream class used to read from files.
7. B.head
head is the first node of a linked list
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.