Tuesday, October 20, 2015

C++ interview Questions for Experinced persons



1. overload new operater.
2. Difference between Op new and new operator
3. Explain placement new and why n when it is used
4. is there a placement delete.
5. Explain the error when new fails
6. malloc vs new
7.what is name mangling
8.what are proxy objects ?
9.what is a local class ,sub class ,nested clasd
10.what is object slicing.
11. What is name hiding
12. Explain vtable in detail
       http://www.go4expert.com/articles/virtual-table-vptr-t16544/
       http://www.learncpp.com/cpp-tutorial/125-the-virtual-table/
13.what is a conversion constructor
14.explain explicit constructor
15.copy constructor vs overloaded assignment operator
16.what are class invariants
17.implement a final class in cpp
18.Write a singleton pattern.is it threadsafe ?where it is used.
19.how stl map is implemented internally??
20.how vector allocate memory or how it works internally.can you write your own vector ?
21.what are smart pointers .unique_ptr vs auto_ptr vs shared_ptr?
22. Queue vs priority queue.can you implement or write your own priority queue.
23. Vector vs list vs deque vs map. Which one should u use under what situation
24.what are function pointers , call back functions. What are advantages
25.list x ;list x(); what is the difference here
26.what is synchronous and asynchronous calls/functions or operations
27.what tools u have used for performace checking.how u detect memory leaks.
   Explain how you can detect memory leak,memory corruption.what is dangling pointer
28.have u worked with gdb ,dbx,valgrind ??
29.overloading on const
30.design patterns used in ur project. Explain and write abstract factory,visitor etc
31.how to remove duplicates from vector with single traversal.
32.why private constructor is used. how to handle exceptions in a constructor ?and do we need to handle exceptions in destructor ??

https://isocpp.org/wiki/faq/exceptions#selfcleaning-members

33.How iterator invalidation works in vector,dq,list
34.efficient method of removing odd elements from vector
33.how to sort a vector containing pair elements
34.how to add an element to the front of a vector
35.difference between map::find() vs map::operator[ ]
36.are pure virtual methods allowed in a template class
37.can we have static virtual function
38. Function pointer vs function objects
39.map vs hash_map
40.why should you use obj.empty() over (obj.size() ==0) to check emptiness
41.difference between conversion function and overloaded function call operator
42. Implement pre and post increment operator.
43.how reserve() , capacity() and resize() works in vector
44.what is infamous swap trick on vector ? How to downsize a vector
45.should we use global find algorithm or member function find() for map/set ?
46.how to call/use base class virtual function by a derived class which has already ovrridden it ?
47.can virtual function be private ??
48.issues with pass by value of a class object
49. Int *p=null ; int &p=null ; are they  wrong/correct ??
50.pimpl idiom
51.How to initialize const member variables of a class ??
52. this vs *this
      http://stackoverflow.com/questions/2750316/this-vs-this-in-c
53.calculate the Size of object of a class
54.Write a non-inheritable class(final class)
      http://www.geeksforgeeks.org/simulating-final-class-in-c/
      http://stackoverflow.com/questions/1366441/final-class-in-c

55.Smart pointers , boost::shared_ptr or std::unique_ptr
  
std::shared_ptr<int> p1(new int(5));
std::shared_ptr<int> p2 = p1; //Both now own the memory.

p1.reset(); //Memory still exists, due to p2.
p2.reset(); //Deletes the memory, since no one else owns the memory.


56. New features in c++14
   auto and lambda,std::move constructor ,forward
57.Why do I need to return *this in an assignment operator function?
   To make assignment such as (obj3 = obj2) = obj1; to work.
58.Cache locality,SFINAE 
59.What is the difference between std::vector<int> x; and std::vector<int> x() ?
  First one declares a variable x of type std::vector. Second one declares a function x which returns       std::vector.
60. How to initialize constant and reference member variable?
  Using initialization list.
61.How would you delete object of singleton class?
  we can follow is “Reference counting” mechanism
62. factory vs Abstract factory
    http://www.codeproject.com/Articles/492900/From-No-Factory-to-Factory-Method
   http://corey.quickshiftconsulting.com/blog/first-post
63.How thread synchronization done for pthreads
     http://www.bogotobogo.com/cplusplus/multithreading_pthread.php
64.How to debug threads in dbx/gdb
65.How to use c code in c++
65.What will the sizes of base and derived class object.
http://www.go4expert.com/articles/size-cpp-class-object-t16676/

class Base
{       char ch;
         int value;
        static double db;
    public:
        Base(){}
        virtual ~Base(){}      
        virtual void func() {}
};

class Derived : virtual public Base
{     int d1;
    public:
       void func(){}      
       virtual void func2(){}
};

Ans: Base b is of size=1byte char+3byte padding+4byte int+1 byte vtable pointer=12bytes
        Derived d=(12 bytes of Base)+ 4 byte Int + 4 Byte for Virtual derivation =20 bytes

66. Write your own C++ like exceptional Handling in c.(oracle second round)

http://www.on-time.com/ddj0011.htm
http://stackoverflow.com/questions/4448677/can-a-c-program-handle-c-exceptions

67.Write a c program to dump data from a table having 20K records.;without using Pro*C.
  OCI ??
    https://github.com/vrogier/ocilib
    https://vrogier.github.io/ocilib/doc/html/group___ocilib_c_api_statements.html
68.How to create rest APIs in c.
69.Implement Stack using two queues.
  http://stackoverflow.com/questions/688276/implement-stack-using-two-queues
  http://www.geeksforgeeks.org/implement-stack-using-queue/

1 comment:

  1. Hi Bru,

    Three cheers to you ! Hooray!!! I feel like I hit the jackpot on C++ interview Questions for Experinced persons

    I tried to move my C code from SUN OS to AIX. It complied sucessfuly on AIX machine where as it throws some memory related error message during run time.

    I look forward to see your next updates.

    Obrigado,
    Irene Hynes

    ReplyDelete