| Other C++ General Interview Questions |
| |
| Question | Asked @ | Answers |
| |
| "How will you merge these two arrays? Write the program
Array: A 1 18 22 43
Array: B 3 4 6 20 34 46 55
Output Array: C 1 3 4 6 18 20 22 34 43 46 55"
| HCL | 5 |
| What is the Diffrence between a "assignment operator" and a
"copy constructor"? | Wipro | 2 |
| Have you used MSVC? What do you think of it? | Google | 2 |
| Do we have private destructors? | Symphony | 9 |
| What is the Difference between "vector" and "array"? | TCS | 6 |
| What are the differences between a struct and a class in
C++? | Wipro | 4 |
| Evaluate:
int fn(int v)
{
if(v==1 || v==0)
return 1;
if(v%2==0)
return fn(v/2)+2;
else
return fn(v-1)+3;
}
for fn(7);
a) 10
b) 11
c) 1
| Quark | 1 |
| How would you stop a class from class from being derived or
inherited?The constructer should not be Private,as object
instantiation should be allowed. | | 14 |
| Explain about profiling? | | 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 |
| tell me about yourself ?i want answer for frehers with
various exasmples? | HCL | 2 |
| Can we use resume in error handling i.e. in the catch block | Infosys | 3 |
| How do I open binary files? | | 1 |
| How to write a program such that it will delete itself after
exectution? | | 1 |
| Shall we use 'free' to free memory assigned by new, What are
the further consequences?? | Symphony | 4 |
| 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 and all can a compiler provides by default? | HP | 3 |
| Find the second maximum in an array?
| HCL | 2 |
| class X
{
private:
int a;
protected:
X(){cout<<"X constructor was called"<<endl;}
~X(){cout<<"X destructor was called"<<endl}
};
Referring to the code above, which one of the following
statements regarding "X" is TRUE?
a) X is an abstract class.
b) Only subclasses of X may create X objects.
c) Instances of X cannot be created.
d) X objects can only be created using the default copy
constructor.
e) Only friends can create instances of X objects.
| Quark | 2 |
| What is the output of printf("%d")? | HCL | 25 |
| |
| For more C++ General Interview Questions Click Here |