| Other C++ General Interview Questions |
| |
| Question | Asked @ | Answers |
| |
| What is a pure virtual function?
Why is it represented as = 0...how is the internal
implementation for the same | CTS | 3 |
| why can't we declare data member of class auto register or
extern | | 1 |
| class basex
{
int x;
public:
void setx(int y) {x=y;}
};
class derived : basex {};
What is the access level for the member function "setx" in
the class "derived" above?
a) private
b) local
c) global
d) public
e) protected
| Quark | 1 |
| What is the difference between static global and global ? | CA | 2 |
| How many lines of code you have written for a single program? | BoA | 1 |
| 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 |
| Write a program to swap 2 chars without using a third
varable?
char *s = "A";
char *p = "B"; | CTS | 1 |
| What is Object Oriented programming.what is the difference
between C++ and C? | Infosys | 5 |
| Explain the difference between 'operator new' and the 'new'
operator? | Lucent | 1 |
| What happens if an exception is throws from an object's
constructor and from object's destructor? | TCS | 2 |
| In a class, there is a reference or pointer of an object of
another class embedded, and the memory is either allocated
or assigned to the new object created for this class. In
the constructor, parameters are passed to initialize the
data members and the embedded object reference to get
inialized. What measures or design change should be advised
for proper destruction and avioding memory leaks, getting
pointers dangling for the embedded object memory
allocation? Please suggest. | GE | 3 |
| How the V-Table mechanism works? | HP | 3 |
| What are the differences between public, private, and
protected access? | Wipro | 3 |
| Given a simple program designed to take inputs of integers
from 1-1000 and to output the factorial value of that
number, how would you test this program? You do not have
access to the code. Please be as specific as possible.
| Microsoft | 2 |
| why the size of an empty class is 1 | | 3 |
| When volatile can be used? | Symphony | 2 |
| 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;
} | | 2 |
| What is the Maximum Size that an Array can hold? | Satyam | 31 |
| what is an array
| | 12 |
| How to construct virtual constructor | Symphony | 4 |
| |
| For more C++ General Interview Questions Click Here |