C++ Interview: Option 1
C++ Interview: Option 1
1.- What will i and j equal after the code below is executed? Explain your answer.
int i = 5;
int j = i++;
2.- Consider the two code snippets below for printing a vector. Is there any advantage of one vs. the other? Explain.
Option 1:
vector vec;
/* ... .. ... */
for (auto itr = vec.begin(); itr != vec.end(); itr++) {
itr->print();
}
Option 2:
vector vec;
/* ... .. ... */
for (auto itr = vec.begin(); itr != vec.end(); ++itr) {
itr->print();
}
4.- How many times will this loop execute? Explain your answer.
unsigned char half_limit = 150;
7.- What is difference between shallow copy and deep copy? Which is default?
#include <iostream>
class A {
public:
A() {}
~A() {
throw 42;
}
};