Wednesday 1 July 2015

C++ interview questions.

Hi All,

It is actually not possible to list out a set of questions and tell that your interviewer will ask questions from that set only, still it is my small initiative, to list out some frequently asked c++ questions.

My request to all readers, please add questions on comment, if I have missed something which you feel is very important.

My aim is whenever anyone wants to go for interview. He/She should not struggle much for c++ language related questions. He/She can just visit here and prepare best for c++ interview questions.

Array -

  1. Why is it recommended to not use array polymorphically, as function parameter? Hint - look at more effective c++ item 3.
  2. How to implement dynamic array? Code - 01,
  3. How you will pass 2-D array to a function argument? Code - 01, 02, 03,

Pointers and reference -

  1. What is the difference between using pointer and reference? Hint - look at more effective c++ item 1.
  2. Reference
    1. Returning reference vs value from overloaded assignment operator. Hint - focus on how many time we will invoke constructor and destructor.
  3. Pointers
    1. We have two functions - void foo(int a); and void foo(char *ptr); and my client code calls it like - foo(NULL); // which foo it supposed to call? Hint - ambiguity, instead use nullptr.
    2. What is smart pointers? implement it. Hint - understand how auto memory type works, what is RAII, use smart pointers in place of raw pointers, so that you will not fall into memory leak condition even exceptions are thrown. Look at more effective c++ item 9, 28.
    3. If we have pointer to array like - int *pInt = new int [4]; and I delete pointer after increment it, like - ++pInt; delete[]pInt; what will happened? Hint - read about control blocks, array of memory have.
    4. What is auto_ptr? Hint - look at more effective c++ item 28, Code 01, .
    5. Why is it recommended to not pass auto_ptr by value? Hint - look at more effective c++ item 28.
    6. Why we should return by reference, while implementing operator *, in auto_ptr? Hint - look at more effective c++ item 28.
    7. What is std::unique_ptr? What is the difference between std::unique_ptr and auto_ptr? Hint - look at effective modern c++ item 18.
    8. What is shared_ptr? Hint - look at more effective c++ item 29
    9. In c++11, can we have shared_ptr pointing to an array? Hint - No, if u want, give your own delete function. Also we can say this is one of the drawback of the smart pointer as they can not detect difference between pointer pointing to object or pointing to an array of object.  
    10. what is week pointer ? 

Casting -

  1. How many type of casting do we have in c++? Hint - look at effective c++ item 27.
  2. When you will use dynamic_cast? real life example.
  3. Tell a condition where you cannot use static_cast.
  4. Why is it recommended to use C++ style of casting over C style of casting in CPP code implementation? Hint - look at more effective c++ item 2
  5. What are basic rule of user defined conversion? Hint - look at more effective c++ item 5
  6. Why is it recommended to minimize casting as much as you can? Hint - look at effective c++ item 27.

String 

  1. Split a string, on the basis of some delimiter. Code - 01, 

C++ general questions -

  1. What is size_t type? Is it platform dependent? Hint - look at effective c++ item 1.
  2. What is preferred among these -> a. pass-by-value b. pass-by-reference, c. pass-by-reference-to-const? Hint - look at effective c++ item 20.
  3. What if you don't return anything from overloaded assignment operator? Hint - you will not be able to perform -> a = b = c =d; For more details look at effective c++ item 10.
  4. What is the difference between structural programming and OOPS?
  5. What is the difference between function overloading and function overriding?
  6. What is name mangling? Is it there in c?
  7. How you will call a c function in c++ code? or How to combine c and c++ code?
  8. What is RTTI? Tell some real time use or RTTI. Hint - look at more effective c++ item 24, Code 01, 02
  9. What is a mutable data member? Hint - look at effective c++ item 3.
  10. Namespace 
    1. What problem does the namespace feature solve?
    2. What is anonymous namespace?
  11. If we are declaring a friend function, what should be the scope of that function? global? or class specific? what is the good practice?
  12. what is functor?
  13. Why is it recommended to prefer, ststic, inline, and enums over #define? Why we should bot replace functions with #define? Hint - look at effective c++ item 2
  14. Why is it recommended to move non-local object to it's own function? or If you have more then one static object, and they have to get construct in some order, how you will make sure, that they get constructed in defined order? Hint - look at effective c++ item 4.
  15. RAII (resource acquisition is initialization)
    1. What is RAII? Hint - look at effective c++ item 13.
    2. How copying behavior works in RAII classes? Hint - look at effective c++ item 14.
    3. Why to provide access to raw pointer in RAII class? What is explicit and implicit conversion in this case and which one is preferred? Hint - look at effective c++ item 15.
  16. What is the problem in mentioned function signature -> process(shared_ptr<className>(new className), priority()); Hint - look at effective c++ item 17.
  17. What is cross DLL problem? Hint - look at effective c++ item 18.
  18. When compiler perform type checking, during compile time or during run time? Hint - look at effective c++ item 41.
  19. What are traits classes? Why we use them? Hint - look at effective c++ item 47.
  20. What is array to pointer decay rule?Are they same - void myFunc(int param[]); and void myFunc(int* param); Hint - look at effective modern c++ item 1.
  21. Extension to previous question, what is function to pointer decay rule? Hint - same as mentioned in question 22.
  22. What is the "volatile" in c++?
  23. Compiler 
    1. How to disable warnings in c++?
    2. Can I use dll build in 2010 in the executable build in 2015?
  24. add

Class -

  1. List out the compiler generated functions for any class. Hint - look at effective c++ item 5.
  2. How you can restrict compile to insert default functions? Hint - there is also another way in c++11, see c++11 questions and also look at effective c++ item 6.
  3. What is rule of 3?
  4. Write a string class or implement your own string class similar to standard string class. Hint - they want to see how you are writing a class which has a pointer (say char *pString). focus on overloaded assignment operator and copy constructor while writing your code. CodeEx01.
  5. How you will handle, self assignment in overloaded assignment operator? Hint - look at effective c++ item 11.
  6. Write the syntax of this pointer. How it looks like? Hint - it is different for const and non const functions.
  7. What will happened when you will delete this pointer? Hint - undefined behavior.
  8. What is object slicing and how to avoid it? Hint - loot at effective c++ item 20, also look at link01.
  9. Initialization
    1. When is it mandatory to use initialization List in C++?
    2. Can a class have a reference variable? If yes, then how you will assign value to reference variable? Hint - use initialization list.
    3. How you will initialize const data member of a class? Hint - look at effective c++ item 2.
  10. Friend
    1. Tell some real scenarios where you have used friend functions. Hint - to overload << operator. CodeEx01.
    2. How to write friend class?
    3. How to instantiate a derived class object, whose base class ctor is private? Hint - use friend function.
    4. Create a singleton class, which is singleton for all, but one specific class can create any number of objects of that singleton class. Hint - use friend function.
  11. Static 
    1. How you will initialize static data member of a class? Hint - look at effective c++ item 2. Code - 01, const static,
    2. What if I declare static data member in header file, and define it there itself? Hint - compilation error. Code - StaticInHeader01,  StaticInHeader02
    3. What is the use of static data member? Hint - it will be visible from all instance of that class. Code 01, 02, 03,
  12. What is the size of empty class?Why at all we create empty class, what is the purpose? What is empty base class optimization (EBO)? Hint - look at effective c++ item 39.
  13. Inline functions
    1. What is inline functions? Detail out the drawbacks and advantage of inline functions. Hint - look at effective c++ item 30.
    2. What is implicit and explicit, inline function declaration?
    3. Can we declare constructor or destructor as inline function? If no, why? Hint - look at effective c++ item 30.
    4. Can we create function pointer of an inline function?
  14. What is composition? How you will implement it? Hint - 

Constructor -

  1. Can we throw a exception from constructor?
  2. What is copy constructor?
  3. What is the difference between deep and shallow copy? Hint - look at effective c++ item 12
  4. When to use copy constructor, in private?
  5. How to inform client that construction of object has failed? Hint - we can set some boolean value isSuccess to false and poisoned the data.
  6. Can we define constructor as virtual function? Hint - no
  7. What is a default constructor? Is that mandatory that compiler will provide default constructor every time if you missed it in your class?
  8. How to restrict compiler from creating default constructor for us? Hint - look at more effective c++ item 4.
  9. Tell some scenarios where we should declare default constructor (zero-argument constructor). Hint - when you are creating array of object and also look at more effective c++ item 4. 
  10. What is a conversion constructor? Hint - single argument constructor will act like, implicit converter, look at more effective c++ item 5.
  11. What is explicit keyword in constructor? Hint - use to solve problem discussed at previous question, look at effective c++ item 24 and more effective c++ item 5.
  12. What will happen when you pass pointer in copy constructor? Hint - not good idea as pointer can be a null pointer. Hint - look at more effective c++ item 1

Destructor -

  1. True or false -> "If base class destructor is virtual, then compiler will insert virtual destructor into derived class."
  2. Can we throw a exception from destructor? or, What will happend if exception occur in destructor? Hint - look at effective c++ item 8 and more effective c++ item 11.
  3. Why do we need virtual destructor? Hint - look at effective c++ item 7.
  4. Is it a good idea to have virtual destructor in base class, when I am inheriting it as private inheritance in by derived class?
  5. Why we declare destructor as pure virtual destructor? Can pure virtual destructor have body? Hint - look at effective c++ item 7.

Operators and operator overloading -

  1. What are conversion operators, and why you should not use them until you have to? Hint - look at more effective c++ item 5.
  2. What is pre-fixed and post fixed operator? overload Increment and Decrements Operator. Hint - look at more effective c++ item 6. This is also a perfect example when it make sense for a function to return const object, and not reference.
  3. In for loop is it ok to use post fix operator ? or Why it is recommended  to use prefix over post-fix? Hint - look at more effective c++ item 6.
  4. Why is it not recommended to overload &&, || , dot (.), comma (,) .. few other as well, operators? Hint - look at more effective c++ item 7. Recommendation - if you don't have good reason to overload any operator don't overload it.
  5. Overload + operator for complex number. It should work for all mentioned case -
    1. complex A, B, C;
    2. c = A + B;
    3. int i = 10;
    4. C = A + i;
    5. C = i + A;
      1. Hint - look at effective c++ item 24.
  6. overload << operator for your class. Code - 01, 02
  7. add
     

Memory management -

  1. How many storage Classes do we have? Hint - link01.
  2. How malloc works? Code - 01, 02, 03, 04,
  3. Can we crate an object from new and delete it from free ?
  4. Overload operator new and delete in global and class scope? Hint - look at more effective c++ item 27.
  5. How free will know the size of object (how much memory it has to free)?
  6. Tell the usage of new, operator new, placement new, delete, operator delete, new[] and  operator new[], in c++. Hint - look at effective c++ item 16 and more effective c++ item 8. Code - Placement new (01,)
  7. How delete[] will know how many objects it has to delete? Hint - look at effective c++ item 16.
  8. Tell some scenarios where you will use placement new.
  9. What is std::new_handler and set_new_handler function? Hint - look at effective c++ item 49.
  10. When it make sense to to overload new and delete operators? Hint - look at effective c++ item 50.
  11. Write class specific new and delete operators. Hint - look at effective c++ item 51 and 52.
  12. Justify statement, "if you have written placement new then you should write placement delete". Hint - look at effective c++ item 52.

Inheritance and Virtual functions (or run-time polymorphism) -

  1. Inheritance 
    1. How many types of inheritance are exist in c++? Hint - Multiple, Multilevel, Hybrid, etc.. 
    2. Justify statement - "if it is inheritance follow is-a model strictly". Hint - look at effective c++ item 32. 
    3. Can we implement inheritance in struct? Hint - Yes
    4. How to make a class, abstract class? What do you mean by abstract class? How you will handle virtual, non-virtual and pure-virtual functions of your base class, into your derived class? Hint - look at effective c++ item 34 and 36
    5. What is Private Inheritance? When we will use it? Hint - look at effective c++ item 39.
    6. What are the differences between private, public and protected inheritance?
    7. When should you use multiple inheritance? Hint - look at effective c++ item 40.
    8. Why run-time polymorphism is very costlier in multiple inheritance? Hint - look at more effective c++ item 24
    9. Describe diamond problem? How you will solve it? Write constructors of all classes.
    10. What is virtual inheritance?
  2. Polymorphism (Virtual) 
    1. What is virtual function and what all things will happens when u create a function as virtual function? Hint - vtbl and vptr.
    2. Why is it recommended to avoid hiding inheritance names? Or names in the derived class will hide the name of base class, under "public inheritance", this is wrong behavior, as public functions of base has to be accessible at any cost.? Hint - In case of overloaded functions. One is virtual and other is non-virtual. Or both are non-virtual. Avoid compilation error in derived class by using derivatives. For more info look at effective c++ item 33.
    3. Can we give definition to pure-virtual function? Hint - look at effective c++ item 34.
    4. We can give by default value to our function parameter, but in the case of inheritance, how it will behave if I give different. by default value, to same function parameter while function overriding? Hint - look at effective c++ item 37.
    5. What is the difference between template class (implicit interface or compile time polymorphism) and virtual class ( explicit interface)? Hint - look at effective c++ item 41.
    6. How we were achieving dynamic binding without virtual? Hint - through functions pointers, in call back function.
    7. What will happen if I call virtual function, from constructor or destructor? Hint - look at effective c++ item 9.
    8. What is vtbl? will derived class's vtbl hold the function pointers of base class's virtual function? 
    9. How vptr pointer looks like? internals (or say syntax).
    10. Can we declare inline virtual functions? Hint - look at effective c++ item 30 and more effective c++ item 24
    11. What will happened when you have run-time polymorphism but you didn't declare destructor as virtual and delete base class pointer?
    12. What if my derived class has virtual function in private? AnsHint - also look at effective c++ item 35, code.
    13. What is the cost of virtual functions and RTTI? Hint - look at more effective c++ item 24.
  3. add

Templates -

  1. Can template class contain virtual or pure-virtual functions ? Hint - Yes.
  2. Can a template class contains template virtual function? Hint - No.  
  3. Detail out all usage of typename. What is nested dependent name? Hint - look at effective c++ item 42.
  4. What is the difference between typename (Hint - need not to be a class)and class (Hint - for classes and structures)in template programming ? Hint - look at effective c++ item 42.
  5. Why we cannot access template base class's function directly in template derived class? Hint - in the derived class templates, refer to names in base class templates via (this pointer) -> or by using using declarative or via scope resolution operator. For more details look at effective c++ item 43.
  6. What is template specialization? When we use it? Hint - look at effective c++ item 43.
  7. Tell drawback of using template? or What is code bloat? Hint - look at effective c++ item 44.
  8. How to implement generalized copy constructor? Hint - look at effective c++ item 45
  9. Justify statement - "implicit conversion via constructor call is not considered during template argument deduction". Hint - Rational<int> result = first * 2; //error, extension to question number 5 of operators and operator overloading (mentioned above) look at effective c++ item 46.
  10. Can we give definition to friend function (non-member function) inside the class? Hint - look at effective c++ item 46
  11. What is template meta-programming?

Exception handling -

  1. What exception safe functions guarantee you and how you will achieve it? Hint - look at effective c++ item 29.
  2. What will happened between try and catch block ? Hint - stack-unwinding 
  3. What is Stack Unwinding in C++?
  4. How to catch all exceptions?
  5. List out some of standard exceptions. Hint - look at more effective c++ item 13.
  6. How does throwing and catching exceptions differ from using setjmp and longjmp?
  7. How you will deal a situation where your constructor has potential to throw an exception? Remember if constructor throws exception, it will become half constructed object and compiler will not invoke destructor on half constructed object. Hint - look at more effective c++ item 10.
  8. What are difference between function call and catch statement? Hint - look at more effective c++ item 12.
  9. Why throwing by copy will create 2 objects, and create object slicing problem? Hint - look at more effective c++ item 12 and 13.
  10. What is re-throw? Hint - it will solve the issue mentioned in problem #8, look at more effective c++ item 12.
  11. Why is it not recommended to catch exception by pointers or base class type and recommended to catch it through reference? Hint - look at more effective c++ item 12 and 13.
  12. Is implicit conversion allowed during catch the exception? Hint - look at more effective c++ item 12.
  13. What is exception specification? Hint - loot at more effective c++ item 14.
  14. What will happened if function void foo() throw(); actually throw exception? Hint - undefined behavior could lead to core dump. Code - 01,
  15. How you can set your own unexpected exception handler? Hint - use set_unexpected(UserDefinedFunctionName) , loot at more effective c++ item 14.
  16. What is the cost of exception? Hint - look at more effective c++ item 15.
  17. Implement no-throw swap, function. Hint - look at effective c++ item 25

I/O -

  1. Print the last K lines of an input file.

Achieve efficiency in c++ 

  1. Know about 80-20 rules. Hint - look at more effective c++ item 16.
  2. What is lazy loading and how we will implement that? Hint - look at more effective c++ item 17.
  3. What is Eager evaluation, how to implement it in c++? Hint - look at more effective c++ item 18. 
  4. What is the cost of temporary object? In what all scenarios they will get created? How you can reduce it? Hint - look at more effective c++ item 19.
  5. What will happen when you pass char array[] to string parameter? Hint - look at more effective c++ item 19.
  6. Will temporary object creation take place during implicit type conversion? If yes, then how you can avoid that? Hint look at more effective c++ item 21.
  7. What is return value optimization? Hint - look at more effective c++ item 20.
  8. How we can minimize the compiler dependencies between files? Hint - look at effective c++ item 31

Techniques (or jugad, in hindi) in c++

  1. Can we have virtual constructors in c++? no! Hint - you can think of factory method design pattern as virtual constructors, and we can mimic them here, to have a feel of virtual constructors (have clone functions). look at more effective c++ item 25. Code VirtualConstructorError, VirtualConstructorThroughClone
  2. How to make non-member function, act like virtual function? Hint - take base class object as function parameter, and perform public operation through that object, while will intern do things polymorphically, for more look at more effective c++ item 25. Code - NonMemberAsVirtual
  3. How can you implement your class such a way, it creates 0 or 1 object only? Or How to limit the number of objects of your class? Hint - if you make constructor private, no object shall be created by client or think of singleton design pattern, look at more effective c++ item 26. Code SingleObj, K-NumOfObjectsOnHeap, K-NumOfObjectsOnStack, K-NumOfObjectsOnHeapNoOneInherit, K-NumOfObjectsOnHeapOutSideClass, CountingBaseClass
  4. How to make a class like no one can inherit it? Hint - look at effective c++ item 39 more effective c++ item 26 + this link. Code - NoInheritance,  
  5. How to make a class which can only create its object on heap (only through new)? If I try to create simple object on stack, it should give me compilation error. Hint - look at more effective c++ item 27, other link, Code OnlyInHeap, 
  6. Once you achieve heap based object implementation, you ristrict your class to being inherited or be part of other class as composition, how would you solve this problem. Hint - look more effective c++ item 27. Code - ,
  7. How to create a class which can allow object creation only on stack not on heap (aposit of question-5). Hint - look at more effective c++ item 27. Code - OnlyInStack, 
  8. After achieving object creation only on stack, you will face same issue, like what will happened in the case of inheritance, will client be able to create derived class object on heap?
  9. Use of proxy classes. Hint - look at more effective c++ item 30. 
  10. How to overload operator [][], to display two dimensional array? Code - OverloadOperator
  11. How to detect operator [], is getting used to display a value or update the value? Code - ReadOrWrite
    1. int arr[MAX];
    2. cout << arr[0] // display
    3. arr[0] = 10 // update
  12. How you can tell operator [] is getting used for read or write operation? Hint - look at more effective c++ item 30.
  13. How you can make function virtual, in the respect to more then two objects? Hint - look at more effective c++ item 31
  14. What is p-impl idiom? Hint - look at effective c++ item 25 and 29. 
  15. Detail out the alternatives to virtual function. Or What is non-virtual interface idiom (NVI)? Hint - look at effective c++ item 35.

Call backs

  1. What do you understand by function pointers? How to declare and use them? Code - 01
  2. Can we call two different function, who has same function signature through one function pointer? Code - 01

Good practice to follow -

  1. Make interface easy to use correct and hard to use incorrect. Hint - look at effective c++ item 18.
  2. How to design your class? Hint - look at effective c++ item 19.
  3. Declare data member in private. Hint - look at effective c++ item 22
  4. If you are library developer, exposing non-member , non-friend function to client code, will give you more flexibility. Hint - look at effective c++ item 23.
  5. Postponed variable definition as long as possible. Hint - look at effective c++ item 26.
  6. Don't return the handler to any private data member of a class. It will also help you in multi-threading environment, specially when you want to put mutex on that data member. Hint - look at effective c++ item 28.

C++11 -

  1. General c++11 concepts.
    1. What is uniform initialization in c++ 11?
    2. How initializer_list<T> works, and when we use it? Code 01,
    3. what is move, how it works? 
      1. List out all default compiler generated functions in c++11.
      2. Write the function signature of move. Hint code 01, 02
      3. Will copy constructor gets created if you have defined move constructor? Or how to make your object not copyable?
      4. Will move constructor gets created if I create copy constructor? Reverse of previous question
    4. How auto works?
      1. What is auto keyword in c++ 11? How does it useful? Hint - look at effective modern c++ item 5. 
      2. How compiler detect the type of auto? How auto type detection is different from template type detection? Can template type detection, detect initializer_listHint - look at effective modern c++ item 2
        1. How type detection are different in below mentioned cases -
            1. Case - 1
              1. const char name[] = "R. N. Briggs";
              2. auto arr1 = name;
              3. auto& arr2 = name;
            2. Case - 2
              1. void someFunc(int, double);
              2. auto func1 = someFunc;
              3. auto& func2 = someFunc;
      3. What is the difference between below mentioned two loops, when we use what? -
        1. for(const auto& i: arr) {...}
        2. for(auto i: arr) {...}
          1. Hint - look at the output of auto by value and auto by reference programs.
      4. Why is it not recommended to use auto with std::vector<bool> return type? What is explicit typed initializer idiom? Hint - effective modern c++ item 6.
    5. Why we use bind in c++?
    6. What is std::function? Hint - a new way of writing function pointers. Code 01, 02
    7. How constexpr works?
      1. Is constexpr always guaranteed to be on compile time?
    8. Can we use delete keyword, to indicate compiler not to generate default functions?
    9. How to force compiler to generate its default function? Hint use - default keyword.
    10. Can I delegate other constructor from any constructor in c++11? Hint - use initialization list , code 01,  
    11. What is enum class? How it works? Hint - added scope resolution operator.
    12. How to make my class, such that no one can inherit from it? Hint use final keyword.
    13. What you we mean by final virtual function ?
    14. Lambda expression
      1. How we can remove functor? Hint - by using Lambda expression 
      2. How to capture all local values in lambda? Hint - use [=]
      3. How you will capture all local values by reference in lambda? Hint - use [&]
      4. How you mention the return type of lambda? Hint -  []() -> bool {}
    15. Literals
      1. Can we have user defined Literals? For ex - height = 3.4cm; hre cm is user defined literals. Hint - usae operator""
      2. What is the limitations of c++ literals? Hint - it works with few primitive data types.
    16. loops
      1. Write enhanced version of for loop.
      2. for_each
    17. override keyword 
      1. When to use override keyword?
      2. What problem override keyword solves, which we has in c++03?
    18. universal reference
    19. Universal reference
      1. What is R-value reference? What is the difference between R-value reference and universal reference? Hint - Code 01,
      2. Can we overload function on the basis of L-value reference and R-value reference?
      3. What is perfect forwarding? Hint - we use it with template, and forward to other function. std::forwared<T>(arg), Code 01,
      4. What is the difference between std::forwared and std::move? Hint - code 01,
    20. When to use remove_refence? And how it works? Hint - Code 01,
    21. nullptr
      1. What is the difference between NULL and nullptr?

    22. add
  2. Template
    1. How compilier detect template types in below mentioned 3 conditions - (Hint - look at effective modern c++ item 1)
      1. Parameter type is a pointer or reference type.
      2. Parameter type is a universal reference.
      3. Parameter type is neither a pointer nor a reference (by value).
    2. What is decltype? When do we use it? How its value changes with the use of operator () ? Hint - look at effective modern c++ item 3.
    3. How you will ensure that the type being deduced is the type you expect? Hint - look at effective modern c++ item 4.
  3. string literal 
  4. add

C++ 14 -

  1. Can we deduct return type of a function from auto? What is the syntax difference when we use decltype to detct the type of function's return value between c++11 and c++14? Hint - look at effective modern c++ item 2 and 3.

STL -

  1. What is the difference between size and capacity in linear containers like vector?
  2. What is the difference between set and map?
  3. What is the different between multimap and map?
  4. What is the difference between map and unordered_map?
  5. What is associative array? How you will implement it?
  6. How you will have a function that can handle any stl container and iterate through it?
  7. How you will delete the value from stl container?
  8. How you can insert a value in map and be sure that value get inserted ? means there will a possibility there is another value already there, so map will not insert new value with same key ?
  9. What insert function will return in MAP container.
  10. Is it possible to have user define key in MAP? Hint - overload > operator.
  11. Added to previous question, is there any other way, we can achieve user defined key but dont overload > operator?
  12. How to use pair<T,T> as key in MAP?  
  13. What is the different between list and vector?
  14. Can we have vector of references?


Multithreading -

  1. Questions on multitheading concepts - 
    1. What do you understand by mutual execution?
    2. What is the difference between process and thread?
    3. How many threads we shall create for our application?
    4. How many types of thread do we have?
    5. What do you understand by join and detach?
    6. How conditional variable works, give some example?
    7. Can we assign weight to threads? If yes, then how we will do it?
    8. Difference between Mutex and Semaphore?
    9. Implement Mutex.
    10. Implement Semaphore.
  2. Questions on Multithreading based implementations - 
    1. Producer-consumer-problem: We will have many producer threads and many consumer threads. Like event driven system, as and when any event occur, your producer thread will create event and add them into event buffer (or queue), your consumer threads will act on those event and respond properly. How you will design the system, as your queue will be shared between producer and consumer.
    2. Read-write-problem: You have common data structure, where many read-write threads access that DS, while updating the data it should not allow reader threads to read it and any number of reader threads can read the data simultaneously.
    3. Suppose you have hundreds of threads, to serve many client request. Design a thread scheduler, and demonstrate how you are going to handle all resources.
    4. You have 3 threads, T1, T2 and T3. How you will make-sure that T1 gets executed first, then T3 and then T2?  Or how you will implement a sequential execution in multi-threading environment?
  3. C++ Specific 
    1. What is future and promise?
    2. What is the difference between std::atomic<bool> type and std::atomic_flag type?
  4. add

1 comment:

  1. Hi Bru,


    Zoooooooom! That’s how speedy and easy this read was! Looking forward to more of such powerful content on #topic!

    I have an 1.7 years of exp in C. I wanted to develop a project from job point point of view which can make a resume much stronger .





    Very useful article, if I run into challenges along the way, I will share them here.


    Obrigado,

    ReplyDelete