| Other C++ General Interview Questions |
| |
| Question | Asked @ | Answers |
| |
| What is object slicing and how can we prevent it? | Tech-Mahindra | 2 |
| when can we use virtual destructor? | HP | 2 |
| write a program in c++ to implement stack using functions
in header file stack.h | Subex | 1 |
| What will happen if when say delete this ? | | 3 |
| Difference between Operator overloading and Functional
overloading? | HP | 3 |
| What are advantages and disadvantages of Design patterns? | IBM | 3 |
| When the design recommends static functions? | Symphony | 1 |
| Find out the bug in this code,because of that this code
will not compile.......
#include <iostream>
#include <new>
#include <cstring>
using namespace std;
class balance {
double cur_bal;
char name[80];
public:
balance(double n, char *s) {
cur_bal = n;
strcpy(name, s);
}
~balance() {
cout << "Destructing ";
cout << name << "\n";
}
void set(double n, char *s) {
cur_bal = n;
strcpy(name, s);
}
void get_bal(double &n, char *s) {
n = cur_bal;
strcpy(s, name);
}
};
int main()
{
balance *p;
char s[80];
double n;
int i;
try {
p = new balance [3]; // allocate entire array
} catch (bad_alloc xa) {
cout << "Allocation Failure\n";
return 1;
} | Impetus | 2 |
| What is the output of:
String a1 = "Hello";
String a2 = "world!";
String* s1 = &a2;
String& s2 = a1;
s1 = &a1;
s2 = a2;
std::cout << *s1 << " " << s2 << std::endl; | Lehman-Brothers | 4 |
| What does '\r' and '\b' mean? Please explain with example.
| | 2 |
| template<class T, class X> class Obj {
T my_t;
X my_x;
public:
Obj(T t, X x) : my_t(t), my_x(x) { }
};
Referring to the sample code above, which one of the
following is a valid conversion operator for the type T?
a) T operator T () { return my_t; }
b) T operator(T) const { return my_t; }
c) operator(T) { return my_t; }
d) T operator T (const Obj &obj) { return obj.my_t; }
e) operator T () const { return my_t; }
| Quark | 1 |
| How to reduce a final size of executable? | | 1 |
| How do you know that your class needs a virtual destructor? | Lucent | 3 |
| wrong statement about c++
a)code removably
b)encapsulation of data and code
c)program easy maintenance
d)program runs faster | | 8 |
| In a class only declaration of the function is there but
defintion is not there then what is that function?
| Hughes | 4 |
| What is the Difference between "C structure" and "C++
structure"? | | 4 |
| Brief explaination about #include<iostream.h>,
cin and cout | | 3 |
| How Virtual functions call up is maintained? | | 2 |
| Why would you make a destructor virtual? | Lehman-Brothers | 3 |
| what is an array
| | 12 |
| |
| For more C++ General Interview Questions Click Here |