Professional Documents
Culture Documents
CS Test Yourself
CS Test Yourself
Q3
----
char *strncpy(char *s1, const char *s2, int n) {
char *p = s1;
const char *p2 = s2;
----
Q6
----
(a) The list destructor is executed when the delete operator is used or when the list class goes out of
scope.
(b) list::~list() {
while (L != nullptr) {
node *temp = L;
L = L->next;
delete temp;
}
}
(c) The node destructor is executed when the delete operator is used or when the node object goes out
of scope.
(d) The default node destructor is sufficient because there aren't any variables within the node class that
require special actions. All that is needed is to delete the memory used by the node object.
node *prev = L;
node *current = L->next;
prev->next = newNode;
newNode->next = current;
}
----
Q8
----
template <typename ContainerA, typename ContainerB>
void copy(ContainerA& A, const ContainerB& B) {
A.resize(B.size());