C++ Interview Questions
- 0of 0 votes
AnswersWhat's the problem with this code ?
- Anonymous October 16, 2010
class A
{
public :
int x,y;
A(int i=0,int j=3):x(i),y(j) { }
};
int main()
{
A a();
cout<<a.x<<a.y;
}| Report Duplicate | Flag | PURGE
C++ - 0of 0 votes
Answerswrite a program/function that converts a decimal number to its Roman numeral representation and vice versa.
- JL October 11, 2010| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer C++ - 0of 0 votes
AnswersWhat is difference between operator overloading and overriding?
- chennavarri October 04, 2010| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer C++ - 0of 0 votes
Answersclass A { int a; void show(){ }; } int main() { A *obj = new A(); printf("\n object size = %d", sizeof(A)); return 0; }
printf() shows OBJ size 4 bytes ( i.e int size). why Function show() size is not included in OBJ size and where that show() information(i.e.. function pointer and implementation) stored ?.
- FIGHTER October 02, 2010 in United States| Report Duplicate | Flag | PURGE
NetApp Software Engineer / Developer C++ - 0of 0 votes
Answers#include<iostream> using namespace std; int A() { return 1; } char A() { return 'a'; } int main() { int a = (int )A(); return 0; }
Interviewer asked me, is it function overloading? . I said no this not function overload then he asked me why ? ( He emphasized on different function return types int and char ) .
- FIGHTER October 02, 2010| Report Duplicate | Flag | PURGE
NetApp Software Engineer / Developer C++ - 0of 0 votes
AnswersHow will you sort 1 million numbers.
- Akshat September 27, 2010
Merge sort or quick sort.
better to use c or C++. Why.| Report Duplicate | Flag | PURGE
Bloomberg LP Financial Software Developer Algorithm C C++ - 0of 0 votes
Answerswhat is problem with this code?#
- Cartman September 25, 2010
#include<iostream>
using namespace std;
const int a[]={1,2,3,4,5};
int b[a[2]];
int main(){}| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer C++ - 0of 0 votes
AnswersWhen is a copy constructor called??
- Cartman September 25, 2010| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer C++ - 0of 0 votes
Answersvoid copystring(char* dest, char *source)
- DashDash September 18, 2010
{
while(*source != NULL)
{
*dest = *source;
dest++;
source++;
}
}
int _tmain(int argc, _TCHAR* argv[])
{
char input[10] = "hello";
char *dest;
dest = &input[1];
copystring(dest, input);
return 0;
}
What is the output of the program...| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer C++ - 0of 0 votes
AnswersFind output of the following code
- Gangadhar September 18, 2010
int
mingle(int a, int b)
{
int c = b/2;
if (b<=1) { return a;}
cout<<c <<endl;
return a*(b-2*c) + mingle(a,c);
}
int
main()
{
int i;
for (i = 1; i<=5 ; i++) {
cout<<mingle(i+1,i-1)<<endl;
}
return 0;
}| Report Duplicate | Flag | PURGE
Microsoft Software Engineer in Test C++ - 0of 0 votes
AnswersQ. There are two linked list that are sorted. We need to merge these lists so that the obtained list is also in sorted order. You should not prepare an extra list for merging the lists.
- Anonymous August 29, 2010
The next question was to write the test cases for testing the program.| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer C C++ - 0of 0 votes
Answersint main() { int i = 32242; int k = find(i); return k; } int find (int j) { if (j > 0) { j = j%10 + find(j/10); printf(" %d ", j); } return j; }
Find the output of the program?
- Anonymous August 29, 2010
Ans: 3 5 7 11 13| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer C C++ - 0of 0 votes
AnswerAsked me about sorting a vector of integers
- Steve August 24, 2010
I told him used std::sort
Then asked me how to sort a vector with objects of class StudentData. I told him use std::sort(ve.begin(), vec.end(), sortRoutine)
The sortRoutine will be define static or global scope in header file.| Report Duplicate | Flag | PURGE
Bloomberg LP Financial Software Developer C++ - 0of 0 votes
AnswersHow will you protect static data?
- Steve August 24, 2010
How do you make sure that static data is protected well enough.| Report Duplicate | Flag | PURGE
Bloomberg LP Financial Software Developer C++ - 0of 0 votes
Answersyou have a base class in which you have private data.There is another class which is derived from base class.How will you access the private data of base class from main() by creating object of derived class.
- surath August 23, 2010| Report Duplicate | Flag | PURGE
Ebay Software Engineer / Developer C++ - 0of 0 votes
AnswersWhat is polymorphism? Can you overload the same operator more than once?
- rk August 20, 2010| Report Duplicate | Flag | PURGE
Bloomberg LP Financial Software Developer C++ - 0of 0 votes
Answersdifference between static and new operator
- rk August 20, 2010| Report Duplicate | Flag | PURGE
Bloomberg LP Financial Software Developer C++ - 0of 0 votes
AnswersWhich one of the following statements accurately expresses the disadvantages
- bingfeng August 16, 2010
of making a function inline?
a) Inline functions always make the program bigger.
b) Inline functions always make the program slower.
c) Inline functions always make the program bigger and slower.
d) It is not possible to take the address of an inline function.
e) It increases compile-time dependencies.| Report Duplicate | Flag | PURGE
Bloomberg LP Software Engineer / Developer C++ - 0of 0 votes
AnswersIn C++, write functions for:
- bjh August 14, 2010
string serialize(vector<string> v);
vector<string> deserialize(string s);
such that a string returned from 'serialize' can be passed into deserialize to get the original set of strings back.| Report Duplicate | Flag | PURGE
Google Front-end Software Engineer C++ - 0of 0 votes
AnswersEvery object of Polymorphic class, contains a Virtual pointer ( which points to Vtable).
- Crime_Master_GoGo August 03, 2010
If I have 1000 objects of a polymorphic class,
why should i waste 1000*4 bytes for storing the same stuff...
All 1000 object contains the exatly same value of virtual pointer...
so the question is why can't this virtual pointer could have been kept in class by complier as it keep all the member function definition somewhere... If a class A has member function func1().. there is only one copy of it ...for all the objects... then why do we have separate copy of virtual pointer for each object...while value is same in all the objects ?
How do you think compiler finds the address of a member function for a non polymorphic class?
Don't you think the same mechanism could have been used to find out the virtual pointer for that class also?| Report Duplicate | Flag | PURGE
C++ - 0of 0 votes
AnswersI was asked what is the size of an empty C++ class.
class A { // No member variable inside // no member function ( doesn't make //difference anyways) }
I answer that it's One byte.. then i was asked immediately why?
- Crime_Master_GoGo August 03, 2010| Report Duplicate | Flag | PURGE
C++ - 0of 0 votes
Answersis there any situation where compiler will not take function as inline(note function is not big)
- sunny July 31, 2010| Report Duplicate | Flag | PURGE
Bloomberg LP Software Engineer / Developer C++ - 0of 0 votes
Answerswhat is zombie
- sunny July 31, 2010| Report Duplicate | Flag | PURGE
Bloomberg LP Software Engineer / Developer C++ - 0of 0 votes
Answerswhat is container
- sunny July 31, 2010| Report Duplicate | Flag | PURGE
Bloomberg LP Software Engineer / Developer C++ - 0of 0 votes
Answerswhat is allocator
- sunny July 31, 2010| Report Duplicate | Flag | PURGE
Bloomberg LP Software Engineer / Developer C++ - 0of 0 votes
Answersis there any other way of declaring const variables
- sunny July 31, 2010| Report Duplicate | Flag | PURGE
Bloomberg LP Software Engineer / Developer C++ - 0of 0 votes
Answershow can we make sure class object is created only on heap and not anywhere else
- sunny July 31, 2010| Report Duplicate | Flag | PURGE
Bloomberg LP Software Engineer / Developer C++ - 0of 0 votes
Answerswhat is inline and macro, difference between them
- sunny July 31, 2010| Report Duplicate | Flag | PURGE
Bloomberg LP Software Engineer / Developer C++ - 0of 0 votes
Answersdifference between static used in c and c++
- sunny July 31, 2010| Report Duplicate | Flag | PURGE
Bloomberg LP Software Engineer / Developer C++