Programming

What is the “sizeof” operator in C C++

sizeof operator is useful operator to get the size of type or variable( auto,pointer, array). Return value of sizeof operator is of type size_t.  Its defined in the file file STDDEF.H. The advantage of using sizeof operator is, you dont need to specify the machine dependent data. 1. When a type is passed, it should be [...]

C# Language : Getting Started

C# is programming language from Microsoft. How different is it from other languages provided by Microsoft, well its managed. If you remember even Microsoft has released a version of Java VJ++ after Sun Java became popular. However after the sued by Sun, Microsoft has stopped releasing any further version of Visual J++. But They come [...]

Example of size() method of HashMap.

A HashMap is class of collection framework.It stores data in the form of name value pair.It provides number of methods.The size() is also a method of HashMap class.It returns the size of HashMap, size means total number of keys in HashMap.

Cleaning up resources with termination handlers

There is certain situation when we need some code must be executed. While working with C++/windows, we have mechanism that makes sure that a specified code block will be executed at any cost. Even if there is a return or goto statement. This is very useful when you have resources to clean up. This is [...]

C++ copy constructor and an overloaded assignment operator

C++ compiler provides you four special functions to every class by default. 1. Default constructor Called while creation of object 2. Copy constructor This is called when a.  an object is passed by value, void setFunction( MyClaa obj); b.  an object is return by value. MyClass getFunction(); c.  new object is created from existing object( [...]

Operator overloading (Compile time polymorphism-static binding)

This is another type of polymorphism also called as compile time polymorphism or static binding. Operator or function overloading essentially means having multiple functions or methods with same name. Operators are the special functions which carry out certain operation on operands, such as equating, comparison, addition, subtraction etc. We know various arithmetic operators, comparison, logical [...]

Various types of Function overloading (compile time polymorphism / static binding)

Polymorphism means same entity behaving differently at different times. Compile time polymorphism is also called as static binding. Compile time or static binding means Function body is bind to the function call at compile time itself.  In C++ compile time polymorphism can be achieved using Function overloading and operator overloading. Function overloading Function overloading means, [...]

What is the use of RAII- Resource Acquisition Is Initialization in C++

C++ program needs resources (variables/Objects) to do something. We can use normal objects created on Stack or we can allocate them dynamically on Heap memory. Constructor code is the guaranteed part which is executed while creating objects. Similarly destructor code is the guaranteed part gets executed when object goes out of scope. If an object [...]

C++ : Explain constructors Usage

To initialize an object of a class, we need a constructor. We can use default constructor provided by compiler or we can overload constructors or override zero argument constructor similar to default constructor. Constructor Ex. Class MyClass { Public: MyClass(); };   It does not have any argument. Unlike normal functions, it doesn’t return any [...]

Why do we need constructors in C++

Prior to C++ programming or Object oriented programming; procedural languages such as C language were used. Procedural language program have typical structure where variables needs to be declared to hold data and functions need to be declared to operate on these variables. To share variables among various parts of program (or with number of functions) [...]

Where does C++ program data stored

Every C++ program has some defined Input, Processing and desired Output.  C++ program contains Data and Operations to operate on data. If you see a memory structure of C++ Program, while loading into the memory, Data Section and Code section is created. But data section is not the only place where program data is stored [...]

How references are different from Pointers

Char * ptr = 0;  // cannot declare char & ref ; char & ref = *ptr; string s (“sdadsf”); string & rstr = s; pointers use  * to declare and -> access member reference use & to declare an . to access member Pointers can be NULL but references cant. Reference dont need to [...]

C++ and Win32 Exceptions

What is an exception? Exception is the special condition that changes the flow of normal execution . Some times te exceptions may endf up crashing the appln ,but it can usually be handled using the catch block in the code.     Basically there are two typpes of exception ,one is the h/w exception & [...]

Problems with C++ assignment operator

Assignment Operator is invoked in following scenarios, where one existing or already constructed object assigned to another constructed object. class MyClass  { int  nSize; char  *szName ; }; MyClass myObj1; MyClass myObj2; myObj1 = myObj2;   // Assignment Operator By default Compiler provides a Assignment operator which will do following operation on assigning myObj2 to myObj1. [...]

C C++ declaration and definition examples

  Declaration means informing the compiler that you have created a particular type of symbol that is being used by your program. Note: this is just an symbol or name that will be inserted into symbol table during compilation pass. No Memory allocates.   Declaration:   int i;               // Variable declaration or object declaration extern [...]