C++ Interview Questions
- 0of 0 votes
AnswersExplain the functionality of malloc...If a pointer ptr is pointing to array of 100 bytes and free(ptr) is called..then How the compiler knows that 100 bytes are to be removed...Explain any other way to optimize this.
- Bhagyashree Kothari December 25, 2009| Report Duplicate | Flag | PURGE
NVIDIA Software Engineer / Developer C++ - 1of 1 vote
AnswersIf I have 2 pointers A pointing to B and B pointing to A. Is it an error?
- emma December 22, 2009| Report Duplicate | Flag | PURGE
Sonoa Systems Testing / Quality Assurance C++ - 1of 1 vote
AnswersExplain the difference between calloc and malloc
- emma December 22, 2009| Report Duplicate | Flag | PURGE
Sonoa Systems Testing / Quality Assurance C++ - 0of 0 votes
AnswersIs static constuctor exist in C++?
- niranjan.singh December 13, 2009| Report Duplicate | Flag | PURGE
C++ - 0of 0 votes
Answersint main()
{int n = 12;
std::cin >> std::hex >> n;
std::cout << std::setprecision(2) <<n;
return 0;
}
- lnpeng December 11, 2009
What would be the output given input is 12?
choice a:
12
choice b:
12.00
choice c:
18
choice d:
18.00
choice e:
1.80e+001| Report Duplicate | Flag | PURGE
Bloomberg LP C++ - 0of 0 votes
Answersclass A {};
void foo()
{throw new A;
}
- c.c. December 11, 2009
Which of the following catch statement is valid?
choice a:
catch (A && e)
choice b:
catch (A e)
choice c:
catch (A * e)
choice d:
catch (A ** e)
choice e:
catch (A & e)| Report Duplicate | Flag | PURGE
Bloomberg LP C++ - 0of 0 votes
AnswersYou have 4 bottles each containing pills that weigh 10 grams each and 1 bottle containing pills that weigh 9 grams each, How would you find out the lighter of the 5 bottles by using a Digital Scale just Once?
- Saurabh December 11, 2009
Hint: He asked to open the bottles and take the pills out, and also grouping them wont work.| Report Duplicate | Flag | PURGE
Bloomberg LP Financial Software Developer Brain Teasers C++ - 0of 0 votes
AnswersWhat is the difference between functors, call back functions and function pointers?
- CK December 09, 2009| Report Duplicate | Flag | PURGE
Yahoo Software Engineer / Developer C C++ - 1of 1 vote
AnswersWrite a function to add an array of numbers.
- June December 03, 2009| Report Duplicate | Flag | PURGE
Yahoo Software Engineer / Developer Application / UI Design Arrays C C++ Coding - 0of 0 votes
AnswersWhat's the difference between assignment operator and copy constructor
- tweety November 20, 2009| Report Duplicate | Flag | PURGE
Yahoo Software Engineer / Developer C++ - 0of 0 votes
AnswersWhat's the difference between pointer and reference
- tweety November 20, 2009| Report Duplicate | Flag | PURGE
Yahoo Software Engineer / Developer C++ - 0of 0 votes
AnswersWhat are call back functions?
- tweety November 20, 2009| Report Duplicate | Flag | PURGE
Yahoo Software Engineer / Developer C++ - 0of 0 votes
AnswersWhat is a functor?
- tweety November 20, 2009| Report Duplicate | Flag | PURGE
Yahoo Software Engineer / Developer C++ - 0of 0 votes
AnswersC++ concepts:
- Anonymous November 20, 2009
Virtual functions
Exception Handling
Casts| Report Duplicate | Flag | PURGE
Bloomberg LP Software Engineer / Developer C++ - 0of 0 votes
AnswersWhat are the disadvantages of using pointer?
- Twitty November 12, 2009| Report Duplicate | Flag | PURGE
Adobe Software Engineer / Developer C++ - 2of 2 votes
Answersfind the longest palindrome in a string?
- handiaya November 09, 2009| Report Duplicate | Flag | PURGE
Microsoft Amazon Software Engineer / Developer Algorithm Arrays C++ Coding String Manipulation C - 0of 0 votes
AnswersWhat are some things to take care of when definining - a) Copy constructor b) Assignment operator?
- NJ October 23, 2009| Report Duplicate | Flag | PURGE
Bloomberg LP Software Engineer / Developer C++ - 0of 0 votes
AnswersGiven char* func1(char* target, char* substring,char* replacement)
- Amit Parikh October 23, 2009
write a c++ code to find the substring in the target and replace the whole substring with the replacement. (hint: replacement can be larger or smaller than the substring.)consider all possible test cases and check.| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer C++ - 0of 0 votes
AnswersWhy do you use virtual functions? What is a VTABLE? How does it work?
- Rohan October 08, 2009| Report Duplicate | Flag | PURGE
Bloomberg LP Financial Software Developer C++ - 0of 0 votes
AnswersHow many constructor (including copy constructor) and destructors will be called for test1 and test2?
- bl September 29, 2009#include <iostream> using namespace std; class Base{ public: Base(){cout << "Base()" << endl;} Base(const Base&){cout << "Base(const Base&)" << endl;} ~Base(){cout << "~Base()" << endl;} }; Base func(Base b){return b;} void test(){ Base a; func(a); } void test(){ Base a; Base b = func(a); } int main(){ test1(); test2(); return 0; }
| Report Duplicate | Flag | PURGE
Bloomberg LP Software Engineer / Developer C++ - 0of 0 votes
Answershow would you know if a map is corrupted?
- mita.baxi September 25, 2009| Report Duplicate | Flag | PURGE
Bank of America Software Engineer / Developer C++ - 0of 0 votes
Answers1) Type of stl containers
- mita.baxi September 24, 2009
2) difference in composition, agregation,association.
3) Predicates
4) Deadlock and Starvation
5) Raised condition
6) Diff in Conversion ctr and explicit ctr
7) diff in has_map and map
8) explain hash_map and bucketing
9) virtaul inheritance, diamond problem
10) function adaptors
11) fucntors
12) function objects
13) in how many ways two classes A and B be related to each other.
14) diff between vector and dqueue
15) Repopulation of dqueue and its complexity.
16) types of iterators
17) how would you implement a map.
18) concept of immutability.| Report Duplicate | Flag | PURGE
Bank of America Financial Software Developer C++ - 0of 0 votes
AnswersGiven two classes:
- offer September 19, 2009
class B
{
public:
B(args_1);
B(args_2);
// and many constructors with different arg lists
};
class D : public B
{
public:
D(args_1) : B(args_1) {}
D(args_2) : B(args_2) {}
// and many constructors with different signatures similarly implemented
// some additional stuff specific to D
};
Assume that the arg list for B's constructors are quite long and may be
revised pretty often in the future, in which case D's constructors have
to be recoded correspondingly. Duplicating the update by copy-and-paste
will certainly work here. Can you propose a better way so that the
update can be done in one place without copy-and-paste duplication?| Report Duplicate | Flag | PURGE
Goldman Sachs Financial Software Developer C++ - 0of 0 votes
Answersclass Base{ int a; public: int b; Base(){a = 10; b = 11;} virtual ~Base(){}; class Derived; friend Derived; }; class Derived: private Base{ public: Derived(){cout<<b<<endl;} void p(Base b){cout<<b.a<<endl;}; virtual ~Derived(){}; }; int main(){ Base b; Derived d; d.p(b); return 0; }
Can this code be compiled and why?
- Anonymous September 10, 2009| Report Duplicate | Flag | PURGE
C++ - 0of 0 votes
AnswersWrite thread safe getInstance function of Singleton class.
- Arang September 08, 2009| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer C++ - 0of 0 votes
AnswersWhy should you not call a virtual method from within a derived class constructor?
- hgk September 04, 2009| Report Duplicate | Flag | PURGE
Qualcomm Software Engineer / Developer C++ - 0of 0 votes
Answersstd::vector<int> items;
- bigbear September 02, 2009
Referring to the sample code above, how do you remove all elements from the items
collections that are greater than 50?
a. items.erase(std::remove_if(items.begin(), items.end(), std::bind2nd(std::greater<int>(), 50)), items.end());
b. std::remove_if(items.begin(), items.end(), std::greater<int>(50));
c. items.erase(std::remove_if(items.begin(), items.end(), std::bindlst(std::less_equal<int>(), 50)), items.end());
d. items.remove_if(items.begin(), items.end(), std::bind2nd(std::greater<int>(), 50)));
e. items.remove_if_greater(items.begin(), items.end(), 50);| Report Duplicate | Flag | PURGE
Bloomberg LP Financial Software Developer C++ - 0of 0 votes
AnswersWhat is hard copy and shallow copy?
- lele August 21, 2009| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer C++