C++ Interview Questions
- 0of 0 votes
AnswersHow does a static member function work?
- Rajarathinam Antony February 06, 2012 in India
Where are they stored in memory?
Where the no static member functions of a class are stored in memory| Report Duplicate | Flag | PURGE
Manhattan associates Software Engineer / Developer C++ - 0of 0 votes
Answers//Error with the following code,can anyone correct the //following code for queue using two stack getting //compilation error in constructor
- anuj.iiit2007 February 05, 2012 in India
#include <cstdlib> // system definitions
#include <iostream> // I/O definitions
#include <fstream>
#include<string>
#include<stack>
#include<vector>
using namespace std; // make std:: accessible
using std::stack;
using std::string;
template<typename T>class Myqueue
{
stack<T> s1,s2;
public:
Myqueue(){
s1=new stack<T>();
s2=new stack<T>();
}
int size()
{
return s1.size()+s2.size();
}
void add(T value)
{
s1.push(value);
}
T peek()
{
if(!s2.empty())
return s2.peek();
while(!s1.empty())
s2.push(s1.pop());
return s2.peek();
}
T remove()
{
if(!s2.empty())
return s2.pop();
while(!s1.empty())
s2.push(s1.pop());
return s2.pop();
}
};
int main()
{
Myqueue<string> str;
/*str.Myqueue();*/
string str1;
str.add("devesh");
str.add("pankaj");
str1=str.peek();
return 0;
}| Report Duplicate | Flag | PURGE
Microsoft Software Engineer in Test C++ - 0of 0 votes
AnswersWhat is containment and aggregation in COM. What happen to the scope of the object been created in both the case, do they die automatically or you need to delete them.
- Interviews January 29, 2012 in India| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer C++ - 0of 0 votes
Answersclass Empty {};
- JeffD January 29, 2012 in United States
Empty e;
What is generated for e? If you look at it in a debugger what will you see?
(This was actually Solomon Page, on behalf of BBG.)| Report Duplicate | Flag | PURGE
Bloomberg LP Software Engineer / Developer C++ - 0of 0 votes
AnswersWhat is wrong with the following code
- Anonymous December 28, 2011 in United States
char * test(int v)
{
char buf[6+1];
switch(v)
{
case 1: strncpy(buf, "Case 1", sizeof(buf));
case 2: strncpy((buf,"Case 2", sizeof(buf));
case 3: strncpy((buf, "Case 3", sizeof(buf));
case deafult: strncpy((buf, "Default", sizeof(buf));
}
return &buf;
}
int main()
{
char * p = test(2);
cout << p << endl;
}
Now one obvious answer is that they are trying to return address of a local variable. Then the question is how to solve this problem without changing the prototype of the function. Global variable and static variable are not the right answers| Report Duplicate | Flag | PURGE
Bloomberg LP C++ - 0of 0 votes
Answersgiven a 10 digit number,find the greatest continuous 4 digit number.
- tejaswibm December 22, 2011 in India
Ex:9164352435
Ans : 9164| Report Duplicate | Flag | PURGE
Iron Mountain Software Engineer / Developer C++ - 0of 0 votes
AnswersWht is oop and comparision with traditional method.
- devshree December 09, 2011 in India
Wht is abstraction?
Diff bet abstract class nd interface nd when u use one?| Report Duplicate | Flag | PURGE
Yahoo Software Engineer / Developer C++ - 0of 0 votes
Answerswhat are the stuffs a compiler provide to a class ?
- lipun4u December 03, 2011 in India| Report Duplicate | Flag | PURGE
Manhattan associates Developer Program Engineer C++ - 0of 0 votes
AnswersThere is a pool of memory with a specific address. How to make sure the object is always created in that part of memory ?
- lipun4u December 03, 2011 in India| Report Duplicate | Flag | PURGE
Manhattan associates Developer Program Engineer C++ - 0of 0 votes
AnswersHow to forbid the creation of object in
- lipun4u December 03, 2011 in India
1>Stack
2>Heap
?| Report Duplicate | Flag | PURGE
Manhattan associates Developer Program Engineer C++ - 0of 0 votes
AnswersHow to restrict a function so that in can't throw any kind of exception ?
- lipun4u December 03, 2011 in India
How to restrict a function so that it can throw the exception of a particular type ?| Report Duplicate | Flag | PURGE
Manhattan associates Developer Program Engineer C++ - 0of 0 votes
AnswersUnder which conditions the default assignment operator
- pavel.em November 14, 2011 in United States
is not generated by the compiler for your class ?
(assuming that you do not declare the assignment operator yourself)| Report Duplicate | Flag | PURGE
Microsoft C++ - 0of 0 votes
AnswersImplement a RandomAccessContainer and its iterator in C++, like std::vector
- lyra_vega November 09, 2011 in -| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer C++ - 1of 1 vote
Answers#include <iostream>
- cinderella November 03, 2011 in United States
#include <vector>
#include <iterator>
#include <algorithm>
#include <functional>
struct base
{
int val ;
base() : val(100) {}
virtual int foo() { return val ; }
} ;
struct derived : public base
{
double val ;
derived() : val(200.2) {}
virtual int foo() { return val ; }
} ;
int main()
{
std::vector<base*> vec( 3 ) ;
derived derived ;
std::fill( vec.begin(), vec.end(), &derived ) ;
std::transform( vec.begin(), vec.end(),
std::ostream_iterator<int>( std::cout, "+" ),
std::mem_fun( &base::foo ) ) ;
return 0;
}
what will be the output of the code above| Report Duplicate | Flag | PURGE
C++ - 0of 0 votes
AnswersIf have allocated an array of integers using new operator. How can the memory be freed using free(not delete) ?
- lipun4u October 21, 2011 in India
If have allocated an array of integers using malloc(not new). How can the memory be freed using delete(not free) ?| Report Duplicate | Flag | PURGE
The Digital Group Developer Program Engineer C++ - 0of 0 votes
Answersassume you have a program which constantly crashes at some place. Yet, if you insert a 'printf' statement at this place, it magically begins to work.
- pavel.em October 16, 2011 in -
What does this indicate ? How can you trace the problem ?| Report Duplicate | Flag | PURGE
Microsoft C++ - 0of 0 votes
AnswersDesign and implement a garbage collector in c++.
- python.c.madhav October 15, 2011 in India| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer C++ - 0of 0 votes
AnswersGiven a 2D array which has elements sorted both row-wise and column wise, find an efficient way to search a given key.
- Avinash October 15, 2011 in India
Ex: a1 a2 a3 a4
b1 b2 b3 b4
c1 c2 c3 c4
a1<a2<a3<a4 (for all rows)
a1<b1<c1 (for all columns)| Report Duplicate | Flag | PURGE
Amazon Goldman Sachs Software Engineer / Developer Applications Developer Arrays C++ - 0of 0 votes
AnswersWrite a program to copy the string?
- Harsh123 October 11, 2011 in India| Report Duplicate | Flag | PURGE
Kalido Software Engineer / Developer C++ - 0of 0 votes
Answershow compiler generates unique names for overloaded functions, if two functions have same name and same parameters but differnt return type , can it be possible i said no he asked why . i explained about the name mangling and showed that return type does not play any role in name mangling.
- getjar.com/todotasklist my android app October 06, 2011 in -| Report Duplicate | Flag | PURGE
Samsung Software Engineer / Developer C++ - 0of 0 votes
Answerstell me about about function pointer , how to call a function using function pointer.
- getjar.com/todotasklist my android app October 06, 2011 in -| Report Duplicate | Flag | PURGE
Samsung Software Engineer / Developer C++ - 0of 0 votes
Answerswhich is faster c or c++.
- getjar.com/todotasklist my android app October 06, 2011 in -| Report Duplicate | Flag | PURGE
Samsung Software Engineer / Developer C++ - 0of 0 votes
Answerswhat are call back functions.Why they are useful.
- getjar.com/todotasklist my android app October 06, 2011 in -| Report Duplicate | Flag | PURGE
Samsung Software Engineer / Developer C++ - 0of 0 votes
Answersif polymorphism is possible in C if yes then how.
- getjar.com/todotasklist my android app October 06, 2011 in -| Report Duplicate | Flag | PURGE
Samsung Software Engineer / Developer C++ - 0of 0 votes
Answerswhat is Vtable explain and give example. design a class and make virtual table for that.
- getjar.com/todotasklist my android app October 06, 2011 in -| Report Duplicate | Flag | PURGE
Samsung Software Engineer / Developer C++ - 0of 0 votes
AnswersImplement Smart Pointer?
- sekhar.amgoth September 26, 2011 in -| Report Duplicate | Flag | PURGE
PayPal Developer Program Engineer C++ - 0of 0 votes
AnswersThis question regarding RTTI in C++..
- sekhar.amgoth September 26, 2011 in -
How dynamic_cast work internally...| Report Duplicate | Flag | PURGE
PayPal Developer Program Engineer C++ - 0of 0 votes
AnswersQuestion on c++ templates...
- sekhar740 September 23, 2011 in India
template <class T>
T max(T a, T b)
{
return ( a > b )? a : b;
}
for built in data types it will work fine .. if we send class objects as parameters then how it will work??| Report Duplicate | Flag | PURGE
PayPal Software Engineer / Developer C++