what's the difference between a binary semophore and a mutex?

1. A semaphore post (or basically unlock) can be performed by a different thread. However, in the case of mutex, it should be unlocked only by the same thread.

2. A semaphore post is always remembered. In other words, a producer thread can signal an unlock even when no consumer thread is waiting for data. In this case, when a consumer thread comes up and tries to block on a call to sem_wait (or locking), it can proceed further and gain control of the semaphore (which had been signalled before by the producer thread). This does not happen with a mutex - any unlock from another thread is lost.

How to implement polymorphism

v-table,

how to implement v-table?

tail

Write a program to display last 'n' lines of an arbitrary length of
file (like tail Unix program).

What is a mutable member?

One that can be modified by the class even when the object of the class or the member function doing the modification is const.

Understanding this requirement implies an understanding of C++ const, which many programmers do not have. I have seen large class designs that do not employ the const qualifier anywhere. Some of those designs are my own early C++ efforts. One author suggests that some programmers find const to be such a bother that it is easier to ignore const than to try to use it meaningfully. No wonder many programmers don't understand the power and implications of const. Someone who claims to have enough interest in the language and its evolution to keep pace with the ANSI deliberations should not be ignorant of const, however.

What is RTTI?

Runtime type identification. The ability to determine at run time the type of an object by using the typeid operator or the dynamic_cast operator.

What is inheritance?

Inheritance is a way to let new classes reuse attributes and behavior of pre-existing classes.

What is abstraction?

It is the act of focusing on the essential features while forgetting specific details for a while.

What is the difference between operator new and the new operator?

This is what happens when you create a new object:
  1. the memory for the object is allocated
  2. the costructor of the class is invoked to properly initialize this memory.
The new operator does both 1 and 2. The operator new only does 1.

What is the difference between C and C++ struct?

  1. C++ structs are like C++ class except the default access for struct is public v/s class is private
  2. C struct can have integral data type only unlike C++ struct that can also have member functions
  3. C struct cannot have access scope like public, private, protected, but C++ struct can.
  4. struct A{ int i, int j } ; typedef A A1; typedef needed for C struct and not required for C++ , A can be directly accessed.

What is polymorphism?

Polymorphism allows a single definition to be used with different types of data.

compile time(function overloading) vs runtime(function overriding)
polymorphic function vs polymorphic data.

What are the different types of Storage classes?

auto, static, register, extern

What is abstract class?

It is a class having at least one pure virtual method.

What is the difference between class and structure?

Members of a structure are public by default, while members of a class are private by default.

What is the difference between macro and inline()?

Inline functions are expanded by compiler, macros are expanded by the preprocessor. In some sense, inline functions are type safe macros.

What is virtual function?

It is a function whose implementation is defined in the deepest subclass.

Why does a copy constructor accept a const reference as parameter?

Because otherwise an infinite call chain would be created. i.e., a copy constructor has to call itself to make a copy of the argument.

What is the difference between "overloading" and "overriding"?

overridding is runtime polymorphism while overloading is compile time polymorphism.

Overloading a method (or function) in C++ is the ability for functions of the same name to be defined as long as these methods have different signatures (different set of parameters). Method overriding is the ability of the inherited class rewriting the virtual method of the base class.

Can we have virtual constructors?

No. Because the type of an object is always known when it is created.

What is the difference between assignment operator and copy constructor?

Copy constructor is a constructor — a function whose job it is to turn raw storage into an object of a specific class. An assignment operator, on the other hand, copies state between two existing objects. In other words, an assignment operator has to take into account the current state of the object when copying the other object’s state into it. The copy constructor is creating a new object from raw storage and knows it’s writing over garbage.

What is virtual destructor?

Virtual destructor allows one to properly destroy an object without knowing its type.