Difference between TCP and UDP

UDP or User Datagram Protocol is the simplest connectionless transport layer protocol which simply sends packets between applications. It has very less overhead as UDP doesn’t require any session to transfer packets between applications.
Generally Real time protocols (RTP), DNS etc application uses UDP protocol.

TCP or Transmission Control Protocol is a reliable, connection-oriented protocol. TCP maintains a session between application and uses this session to send data across applications. TCP has support of acknowledgements of every packet being transferred and hence it’s reliable protocol but has higher overhead compared to UDP.
Generally FTP, HTTP etc application uses TCP protocol.

(more…)
Difference between TCP and UDP Read More

std::bitset explained with simple example

A Bitset is a standard template library class provided by C++ which can be used to define a fixed length sequence of bits. A value of zero indicates bit is unset whereas 1 indicates bit is set.
This class provides similar functionality as array of Boolean values in more space efficient way. There are lot of useful memory functions also provided by the library which can be used by the programmers to use it directly.

Let’s have a look into std::bitset template class definition.

template <size_t N> class bitset;
Where N = length of bitset (in bits).
(more…)
std::bitset explained with simple example Read More

std::vector explained with simple example

Vector in C++ are part of Standard Library Container Classes which basically has the functionality of dynamic array which are flexible in size.
C++ STL provides a template class definition for Vectors which are very efficient, refined, and easy to use.
It also has lots of very useful member functions which can be used directly in programs for faster implementation.

Let’s have a look into std::vector class template definition.

template <class T, class Allocator = allocator<T>> class vector
where T = data type that is being stored and allocator defines the allocator functions.
(more…)
std::vector explained with simple example Read More

Difference between Copy constructors and Assignment operator

Copy constructor is a special kind of constructor which initializes an object using another object. Compiler always provides a default copy constructor but if needed it can be over-ridden by programmer to meet the requirements.

Assignment operator is basically assigning the new values to already created object. In this case object initialization doesn’t happen as it is already done.

For eg:

class Base{
};

Base b1;
Base b2 = b1; /* Copy constructor as initialization also needs to done */
Base b3;
b3 = b2; /* Assignment operator as object is already created */
(more…)
Difference between Copy constructors and Assignment operator Read More

Difference between Constructors and Destructors

Constructor

Constructors are special member functions of a class which is used to initialize the object in desired way. Constructors has the same name as that of class. There could be multiple constructors defined in a class which could be selected based on invoking conditions.

Types of constructor

  • Default constructor – Any constructor without argument is called default constructor.
  • Parameterized constructor – Any constructor in which argument can be passed is called Parameterized constructor.
  • Copy constructor – This is a special kind of constructor which uses an existing object to create a new object.

Destructor

Destructor is a special member function of a class which is used to delete the object. Destructor also has the same name as that of class prefixed with “~” sign. In any class, one could define only one destructor. Destructor doesn’t take any argument.

(more…)
Difference between Constructors and Destructors Read More

Smart Pointers Explained With Simple Example

Standard library included with C++ compilers provides some specific resource management pointers classes which are also called as Smart Pointers.

A normal (raw) pointer typically points to an object, but it doesn’t indicate who owns the objects. This leads to the confusion most of the times, that who is supposed to delete the pointer and free the memory.
Also, by looking into the pointer, one can’t guess how the pointer should be deleted.

Smart pointers are designed to overcome these shortcomings of raw pointers.

Types of Smart Pointers

  • unique_ptr -> This pointer class has the exclusive ownership.
  • shared_ptr -> This pointer class has the shared ownership.
  • weak_ptr -> This pointer class is used with shared_ptr and it doesn’t have any ownership. This pointer is typically used to break loops into circular data structures.
(more…)
Smart Pointers Explained With Simple Example Read More