C++ Interview Questions
- 0of 0 votes
Answersdifference between deque and vectors. where deque can be preferred over vector? how deque is insert element works?
- Sach July 24, 2012 in India| Report Duplicate | Flag | PURGE
Igate Technical Architect C++ - 0of 0 votes
Answers#include <iostream> using namespace std; class base{ public: virtual void func(int i,int j=10) { cout<<"base func"<<endl; } }; class der:public base { public: void func(int i,int j) { cout<<"der "<<j<<" func"<<endl; } }; int main() { der dd; base *bb = new der(); bb->func(10); dd.func(10,1); }
What is the output of this.
- gs July 13, 2012 in India| Report Duplicate | Flag | PURGE
C++ - 0of 0 votes
Answershow can you implement an abstract class in c++ without using pure virtual functions....??
- himanshu June 25, 2012 in India| Report Duplicate | Flag | PURGE
Adobe C++ - 0of 0 votes
AnswersYou have a library provided by the vendor. All you have is header files and library files.
- anuj.iiit2007 June 06, 2012 in United States
Library contains the class Shape and there is whole hierarchy tree (i mean classes which derive from this base class).
Now you want to add some function "getArea" (not originally present in the class or any of its derived class) in the class "Shape" , you dont have the source code.
Using this library, you have written a lot of code. Now you have to make some changes so that, any object of Shape class (or its derived class) will be able to call this function.
With your strategy, you should be able to override the definition of this function in the derived class.| Report Duplicate | Flag | PURGE
C++ - 0of 0 votes
Answersint count = 0;
- Itcecsa May 25, 2012 in United States
for(int i=0; i < 10; ++i)
count = count++;
std::cout << count;
what is the output for the above c++ code?| Report Duplicate | Flag | PURGE
Bloomberg LP Financial Software Developer C++ - 0of 0 votes
AnswersWe have
- DashDash May 16, 2012 in India for Development
char *p = "abc";
I know we cant do p[0] = 'a'. What is the reason behind it?| Report Duplicate | Flag | PURGE
Software Engineer / Developer C++ - 3of 3 votes
AnswersQ1.- Written exam (Amazon, Bangalore)
- Nitin Gupta May 12, 2012 in India
Given a singly link list and a number 'K', swap the Kth node from the start with the Kth node from the last. Check all the edge cases.
Sample Input: 1->2->3->4->5->6->7->8 and K = 3
Sample Output : 1->2->6->4->5->3->7->8
Sample Input: 1->2->3->4->5->6->7->8 and K = 10
Sample Output: print error "LIST IS OF LESSER SIZE".| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm C C# C++ Coding Data Structures Java Linked Lists - 0of 0 votes
AnswersQ2. F2F Round-1, Amazon(Bangalore)
- Nitin Gupta May 12, 2012 in India
Given an array of integers having the property that first that array is strictly increasing then it is strictly decreasing, You have to search for a given number.
Constraint: Minimize the complexity| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm Arrays C C# C++ Coding Data Structures Java - 0of 0 votes
AnswersQ1. F2F Round 1 Amazon(Bangalore)
- Nitin Gupta May 12, 2012 in India
Given a character array as input. Array contains only three types of characters 'R', 'G' and 'B'. Sort the array such that all 'R's comes before 'G's and all 'G's comes before 'B's.
Constraint :- No extra space allowed(except O(1) space like variables) and minimize the time complexity.
You can only traverse the array once.| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm Arrays C C# C++ Coding Data Structures Java Sorting - 0of 0 votes
AnswersQ4. Written Exam Amazon(Bangalore)
- Nitin Gupta May 12, 2012 in India
Given an array of integers A[1....n-1] where 'N' is the length of array A[ ]. Construct an array B such that B[i] = min(A[i], A[i+1], ......., A[i-K+1]), where K will be given.
Array B will have N-K+1 elements.
Constraint: Extra space allowed O(K) and time complexity allowed O(N.K) or lower.| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm Arrays C C# C++ Coding Data Structures Java Sorting - 1of 1 vote
AnswersQ3. Written Exam Amazon(Bangalore)
- Nitin Gupta May 12, 2012 in India
Given a singly linked list which may or may not contain loop and loop may or may not start from the head node. Count the number of elements in the linked list.| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm C C# C++ Coding Data Structures Java Linked Lists - 0of 0 votes
AnswersQ2. Written Exam Amazon(Bangalore)
- Nitin Gupta May 12, 2012 in India
Given a number in the form of string. Output the binary equivalent of that number.
Sample Input: "8.5"
Sample Output: 1000.1
Sample Input: "12.34.23"
Sample Output: "ERROR"| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm C C# C++ Coding Java Math & Computation - 0of 0 votes
Answersimplement shared_ptr in C++
- Itcecsa May 11, 2012 in United Statestemplate <class T> class shared_ptr { private: T* _t; int *count; public: shared_ptr(T* t){ _t = t; count = new int(1); } template <class D> shared_ptr(shared_ptr<D>& d){ _t = d.Get(); count = d.GetCount(); *count = (*count)+1; } ~shared_ptr() { *count = (*count)-1; if(*count == 0) delete _t; } template <class D> shared_ptr<T>& operator= (shared_ptr<D>& d) { if( this->Get() != d.Get() ) { *count = (*count)-1; if( *count == 0) delete _t; _t = d.Get(); count = d.GetCount(); *count = *count + 1; } return *this; } T* Get() { return _t; } int* GetCount() { return count; } };
| Report Duplicate | Flag | PURGE
Morgan Stanley Financial Software Developer C++ - 0of 0 votes
Answerswhile reading a binary file with over 1 billion unsigned integers, how can you optimize the following code to make it perform better?
- Itcecsa April 07, 2012 in United States
int i=0;
long sum=0;
ifstream file("binary.dat", ios::in|ios::binary);
if(file.is_open())
{
while(!file.eof()) {
file.read(reinterpret_cast<char*>(&i), sizeof(unsigned int));
sum += i;
i = 0;
}
}
file.close();| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer C++ - 0of 0 votes
Answerswhy do we need weak_ptr? give an example by code!
- Itcecsa April 06, 2012 in United States
I didn't answer the question well.
I am really confused about weak_ptr. weak_ptr is an observer of shared_ptr, meaning that we always need shared_ptr in order to use weak_ptr. but in cyclic case, we don't use shared_ptr for one of the object, then in this case how can we use weak_ptr without shared_ptr to break cycle?| Report Duplicate | Flag | PURGE
Bloomberg LP Software Engineer / Developer C++ - 0of 0 votes
AnswersDescribe in detail what new operator does, elaborate on memory allocators, kernel free page requests and cascading constructor calls in case of derived classes.
- Blahfoo April 02, 2012 in India for SRE| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer C++ - 0of 0 votes
Answerwhat's the signature of [ ] in std::map? why not const?
- Itcecsa March 30, 2012 in United States| Report Duplicate | Flag | PURGE
Bloomberg LP Software Engineer / Developer C++ - 0of 0 votes
Answerswhat's the advantages of using vector than c array(heap)? what's the difference of the memory models? how is vector more efficient than c array?
- Itcecsa March 30, 2012 in United States| Report Duplicate | Flag | PURGE
Bloomberg LP Software Engineer / Developer C++ - 0of 0 votes
Answerswhat is the result of 16>>2 ?
- ankur.kumar2332 March 30, 2012 in India| Report Duplicate | Flag | PURGE
C++ - 0of 0 votes
Answers#define square(X) X*X
- ankur.kumar2332 March 30, 2012 in India
sq=square(2+3)
what will be the value of 'sq' after the above code is executed ?| Report Duplicate | Flag | PURGE
C++ - 0of 0 votes
Answers#include<stdio.h>
- ankur.kumar2332 March 30, 2012 in India
int main()
{
printf("BCA II");
main();
retrun 0;
}
how many times the above program will print "BCA II" ?| Report Duplicate | Flag | PURGE
C++ - 0of 0 votes
AnswersThere is a monkey which can walk around on a planar grid. The monkey can move one space at a time left, right, up or down. That is, from (x, y) the monkey can go to (x+1, y), (x-1, y), (x, y+1), and (x, y-1). Points where the sum of the digits of the absolute value of the x coordinate plus the sum of the digits of the absolute value of the y coordinate are lesser than or equal to 19 are accessible to the monkey. For example, the point (59, 79) is inaccessible because 5 + 9 + 7 + 9 = 30, which is greater than 19. Another example: the point (-5, -7) is accessible because abs(-5) + abs(-7) = 5 + 7 = 12, which is less than 19. How many points can the monkey access if it starts at (0, 0), including (0, 0) itself? There is no input for this program.
- techieZone March 18, 2012 in United States
Print out the how many points can the monkey access. (The number should be printed as an integer whole number eg. if the answer is 10 (its not !!), print out 10, not 10.0 or 10.00 etc)| Report Duplicate | Flag | PURGE
Software Engineer / Developer Algorithm C++ Coding Data Structures - 0of 0 votes
AnswersGiven the following code snippet:
- ddg March 14, 2012 in United States
class A {
public:
virtual void foo() = 0;
}
class B : public A {
void foo(){};
}
Create a diagram displaying the virtual table mechanism| Report Duplicate | Flag | PURGE
Bloomberg LP Software Engineer / Developer C++ - 0of 0 votes
AnswersGiven the following definition:
- ddg March 14, 2012 in United States
class C{};
How much space gets allocated?
What methods get created?| Report Duplicate | Flag | PURGE
Bloomberg LP Software Engineer / Developer C++ - 0of 0 votes
AnswersGiven the following definition:
- ddg March 14, 2012 in United States
class C{};
How much space gets allocated?
What methods get created?| Report Duplicate | Flag | PURGE
Bloomberg LP Software Engineer / Developer C++ - 0of 0 votes
Answers#include<iostream>
- swarnx February 27, 2012 in India
using namespace std;
class A
{
public:
virtual void f() = 0;
};
class B: public A
{
public:
void f()
{
// f(); //segmentation Fault
cout<<"\bB's f() called"<<endl;
f(); //recursive loop
}
};
void A:: f()
{
cout<<"\nA's f() called"<<endl;
}
int main()
{
A *ptr;
B b;
ptr = &b;
b.f();
return 0;
}
Q-> In this problem.. inside the B class f( ), if we call f( ) before "cout<<" statement it gives segmentation fault and after "cout<<" statement it gives recursive loop. Why segmentation fault is coming. Thanks in Advance :)| Report Duplicate | Flag | PURGE
Software Engineer / Developer C++ - 0of 0 votes
AnswersThere's a major problem in the implementation of the following class. Can you spot it? How can you fix
the problem? You can propose more than one solution, depending on the requirement specifications of
the class.
- marcind February 26, 2012 in United States#include<iostream> using namespace std; template <class T> class Array { private: T *m_pData; unsigned int m_nSize; public: Array(unsigned int nSize) : m_nSize(nSize) { if(m_nSize > 0) m_pData = new T[m_nSize]; } virtual ~Array() { if(m_pData != NULL) delete [] m_pData; } bool Set(unsigned int nPos, const T& Value) { if(nPos < m_nSize) { m_pData[nPos] = Value; return true; } else { return false; } } T Get(unsigned int nPos) { if(nPos < m_nSize) return m_pData[nPos]; else return T(); } };
| Report Duplicate | Flag | PURGE
C++ - 0of 0 votes
AnswersWrite a C++ program that connects to a MySQL server and displays the global TIMEZONE.
- javaprogrammer February 19, 2012 in India| Report Duplicate | Flag | PURGE
Wipro Technologies Software Engineer / Developer C++