C++ Tutorials

scanf

February 14, 2010 // 0 Comments

Though scanf and printf are the functions of legacy C language, these functions are being used extensively even in C++ programs. The programmers who have grown from C to C++ still have the obsession towards C functions like this. This print explains how to use the scanf functions for achieving basic functionalities, whether C or [...]

Copy constructor is a constructor function with the same name as the class used to make deep copy of objects. There are 3 important places where a copy constructor is called. When an object is created from another object of the same type When an object is passed by value as a parameter to a [...]

Operator overloading is a beautiful concept in C++. At times it is little confusing also. But actually they are quite easy. Anyway, here is an example for overloading the stream operators. The best way to overload the stream operators is not to make them members of any class, but to keep them as friends. i.e., [...]

   C++ overloading clearly advocates simplicity in usage and readability. That is why all forms of operators are getting overloaded to give natural and domain oriented meanings. The increment operator ++ can be called in two forms post fix and pre fix. The programmers will have a slight difficulty in overloading/using it because, they won’t [...]

   C++ overloading is the mechanism by which the language standard operators are used for customized operations of the classes. For example if we are trying to write a string class, we would very simply ask for “+” operator to handle string concatenation, “-” for removing one part of string from another etc., This will [...]

   Ask any programmer, he’ll immediately reply saying “A destructor is a member function of a class, which gets called when the object goes out of scope”. This means all clean ups and final steps of class destruction are to be done in destructor. A virtual function is something which helps a derived class in [...]

The concept of a Virtual Destructor is also covered. What is a Virtual Function? A virtual function is a member function of a class, whose functionality can be over-ridden in its derived classes. It is one that is declared as virtual in the base class using the virtual keyword. The virtual nature is inherited in [...]

A function is written in C++ when there’s a certain chunk of code that will be executed more than once, or maybe even just to separate a certain chunk of code from the rest of the code. For example, to convert degrees Celsius to degrees Fahrenheit: //Sample code for functions in C++ float CtoF(float val) [...]

We can define a variable in C++ to store a memory address. A pointer in C++ is said to “point to” the memory address that is stored in it. Also, when defining a C++ pointer variable, we must specify the type of variable to which it is pointing. For example, to define a pointer, which [...]

1 2 3