Posts tagged ‘programming’

Hello world c++

Q1: What value will be printed ?
double d1 = 16, d2=2.0;
double d3 = (1/2) * ( sqrt(d1) + d2/2);
cout << d3 << endl;

Q2: Please write your own itoa implementation

Q3: What is pure virtual destructor? Shall ( or can ) pure virtual functions be implemented ?

Q4: Give an example of abort function implementation

Q5: Why we need semicolon after closing bracket in C++ class declaration ?

Q6: Can we call destructor directly? For what we may need it ?

Q7: Can we call constructor directly? For what we may need it ?

Q8: Can we thron an exception in destructor ?

Q9: What happen if we call pure virtual methods in constructor or destructor ? Same question about ‘non-pure’ virtual methods ?

Q10: Why don’t we have virtual constructors in C++ ?

Q11: What is difference between new and new [] ? Same thing about delete and delete [] ?

Q12: What is a difference between static_cast, dynamic_cast, reinterpret_cast and const_cast ?

Q13: Why do we need explicit keyword in C++ ?

Q14: Explain difference between

const MyClass c;
const MyClass &c2 = c;
const MyClass *c2 = &c;
const MyClass * const c2 = &c;

Q15: Difference between const_iterator and iterator

Q16: Implement Rand5 ( which returns randomly 0..4 ) use only Random7 ( which returns 0..6)

Q17: Can we use object of class ( or structure ) which doesn’t have name? Can we declare and use classes and structures without names ?

Q18: What is it factory pattern ?

( to be updated and continued very soon 🙂

Answers ( if you need it 🙂 ) below Continue reading ‘C/C++ interview questions’ »