Quick Revision: Functions in c++

Hi, guys this is short but very smart understanding for functions in c++ programming language. You can learn this in very simple way and lucid way we have explained the functions. C++ functions are the building blocks of the C++ programs. The main function of the function is to hold the executable code of our written program. The entry and the exit of any C or the C++ program is usually done in the main function. The main function as its name suggest is the basic main function of your program it is used…Read more
Introduction to C++

Introduction to C++

C++: C++ is a programming language. It was first seen in the year 1980’s.C++ is an object oriented programming language it has more advantages and benefits then the simple C language. There are C++ definitions’ and compilers which have made the object oriented programming simpler and much easier. C++ is now the world’s most contemporary mini and micro computer applications are written. It was initially developed in the   AT&T’S laboratories whose first version was BCPL of what later came to be known as the C language and then further with more modifications and…Read more

Virtual Destructors in C++

We cannot use the virtual keyword with constructors, but destructors can and often must be virtual. The constructor has the special job of putting an object together piece by piece, first by calling the base class constructor, then the more derived class constructors in order of inheritance. Similarly, the destructor has a special job: it must disassemble an object that may belong to a hierarchy of classes. To do this, the compiler generates code that calls all the destructors, but in the reverse order that they are called by the constructor. That is,…Read more

Polymorphism & Virtual Functions in C++

What is polymorphism? Object oriented programming language supports the concept of polymorphism which is characterized by the phrase “one interface multiple methods “. In simple term polymorphism is the attribute that allows one interface to control access. in another words polymorphism means to take more than one form . For example an operation may demonstrate different behaviour according to the exact nature of situation .  For example consider operation draw a shape if there are three operands then it will draw a triangle, if there are two operands then operation will draw line.…Read more

Principles of OOP

CLASS Class is made of data and functions. OBJECTS Objects are basic run time entity in object oriented system. They represent a place, a bank account,  or person.  Objects are the instance of class or a variable of user defined data types. When you declare a class there is no memory for data, after creation of class memory is allocated for data and this process is called as instantiation. Each object has its own copy of instance variable of its class. It means any changes to the variable of one object have no…Read more

Dynamic memory allocation and de-allocation in C

Dynamic memory allocation:- void *mallc(size_t size); void *calloc(size_t n, size_t size); void *realloc(void *ptr, size_t size); void *alloca(size_t size); void free(void *ptr); void *memset(void *s, int c, size_t n); int or void *memcmp(const void *s, const void *d, size_t n); void *memcpy(void *dest, const void *src, size_t n); void *memchr(const void *s, int c, size_t n); Important points:- malloc(), calloc() and realloc gets the memory on the heap. In case of static memory allocation, memory is allocated on the stack. We can not change a size of a statically allocated memory. We also…Read more

Namespace and Templates in C++

Namespace:- There is a team development in C++ for creating a single application. Due to this team development different team members may use a same identifier for the function or any data types. Due to this same name compiler generates ambiguity error. To remove this error we have to use the concept ‘namespace’. ‘namespace’ is a work area or a declarative region that attaches an additional identifier to any names declared inside that appropriate namespace. In C++, there is default namespace as std and we are going to provide user defined namespaces under…Read more

Dynamic memory allocation in C++

Dynamic memory allocation:- In C, we can allocate dynamic memory by using malloc, calloc ande realloc library functions. All the above functions are applicable in C++. But there are some disadvantages in C++. To avoid those disadvantages C++ provides its own memory allocation and de-allocation mechanism For dynamic memory allocation in C++ we have to use ‘new’ operator and to de-allocate that memory we have to use ‘delete’ operator. When we allocate a memory by using ‘new’ then we can not de-allocate a memory by using free(). ‘new’ operator internally calls malloc and…Read more

Virtual Destructors and function chaining in C++

Virtual Destructor:- As like a normal function we can create a destructor as virtual. If the class contains at least a single virtual destructor then VPTR is created and it is initialized with appropriate v-table. Virtual destructors are necessary if there is an inheritance and up casting concept is used. If virtual destructors are not written then there is a chance of a memory leak. e.g. class base { public: base() { cout<<”base class constructor.”; } ~base() { cout<<”base class destructor.”; } }; class derived:public base { derived() { cout<<”derived class constructor.”; }…Read more

Operator overloading in C++

Operator overloading:- Operator overloading is a syntactic sugar. It is the type of compile time polymorphism. Overloaded operators are used for class objects or other data members other than basic data types. When we overload an operator we do not have to call explicitly that overloaded function. It is a rule that, 1)    Do not change the meaning of previously defined operator (but we can change the meaning). 2)    Do not change precedence and associatively of that operator. We can provide an overloaded function of an operator as a member function or a…Read more