| Other C++ General Interview Questions |
| |
| Question | Asked @ | Answers |
| |
| What is a constructor initializer list and when we use
constructor initializer list?
| TCS | 2 |
| how to swap two numbers with out using temp variable | | 6 |
| What compiler was used?
| Intel | 3 |
| What is the Difference between "printf" and "sprintf"? | iSoft | 2 |
| What is problem with Runtime type identification?
| | 1 |
| Implement strncpy | | 2 |
| What is difference between initialization and assignment? | HP | 4 |
| How to reduce a final size of executable? | | 1 |
| class Foo {
int x;
public:
Foo(int I);
};
If a class does not have a copy constructor explicitly
defined one will be implicitly defined for it. Referring to
the sample code above, which one of the following
declarations is the implicitly created copy constructor?
a) Foo(Foo *f);
b) Foo(Foo &f);
c) Foo(const Foo *f);
d) Foo(const Foo &f);
e) Foo(int);
| Quark | 3 |
| class HasStatic {
static int I;
};
Referring to the sample code above, what is the appropriate
method of defining the member variable "I", and assigning it
the value 10, outside of the class declaration?
a) HasStatic I = 10;
b) int static I = 10;
c) static I(10);
d) static I = 10;
e) int HasStatic::I = 10;
| Quark | 1 |
| difference between c and c++? | Infosys | 6 |
| In a class only declaration of the function is there but
defintion is not there then what is that function?
| Hughes | 4 |
| class Alpha {
public:
char data[10000];
Alpha();
~Alpha();
};
class Beta {
public:
Beta() { n = 0; }
void FillData(Alpha a);
private:
int n;
};
How do you make the above sample code more efficient?
a) If possible, make the constructor for Beta private to
reduce the overhead of public constructors.
b) Change the return type in FillData to int to negate the
implicit return conversion from "int" to "void".
c) Make the destructor for Alpha virtual.
d) Make the constructor for Alpha virtual.
e) Pass a const reference to Alpha in FillData
| Quark | 1 |
| How to stop conversions among objects? | Symphony | 1 |
| How long does this loop run:
for(int x=0; x=3; x++)
a) Never
b) Three times
c) Forever
| Quark | 8 |
| What are the basics of classifying different storage types,
why? | Symphony | 1 |
| what is the behaviour of C and C++ compiler for the below
statements.
int *p;
p = malloc(100);
Is the behaviour same ? or different ? | | 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 |
| Is there something that we can do in C and not in C++? | Patni | 5 |
| 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 |
| |
| For more C++ General Interview Questions Click Here |