0% found this document useful (0 votes)
49 views3 pages

C++ Interview: Option 1

The document contains 10 C++ interview questions covering topics such as: 1. The values of i and j after int i = 5; int j = i++ is executed (i will equal 5 and j will equal 5, as i++ is a post-increment operator). 2. The advantages of different ways of printing a vector (there is no advantage to either option shown). 3. The difference between a class and struct in C++ (a class is private by default, while a struct is public by default).

Uploaded by

Ab Sba
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views3 pages

C++ Interview: Option 1

The document contains 10 C++ interview questions covering topics such as: 1. The values of i and j after int i = 5; int j = i++ is executed (i will equal 5 and j will equal 5, as i++ is a post-increment operator). 2. The advantages of different ways of printing a vector (there is no advantage to either option shown). 3. The difference between a class and struct in C++ (a class is private by default, while a struct is public by default).

Uploaded by

Ab Sba
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

C++ Interview

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();
}

3.- Is there a difference between class and struct?

4.- How many times will this loop execute? Explain your answer.
unsigned char half_limit = 150;

for (unsigned char i = 0; i < 2 * half_limit; ++i)


{
// do something;
}
5.- What is encapsulation and when to use it?

6.- What is the difference between static and extern?

7.- What is difference between shallow copy and deep copy? Which is default?

8. What is realloc() and free()? What is difference between them?


9. Implement a template function IsDerivedFrom() that takes class C and class P as template parameters. It should return true
when class C is derived from class P and false otherwise.

10. What is the output of the following code:

#include <iostream>

class A {
public:
A() {}
~A() {
throw 42;
}
};

int main(int argc, const char * argv[]) {


try {
A a;
throw 32;
} catch(int a) {
std::cout << a;
}
}

You might also like