Enumeration in C is a convenience feature added to make coding easy. By use of enumeration, or more appropriately enum, a lot of hassle is simplified and code can be made easier to understand. Enum is a user-defined type used to store set of named constants called as enumerators. enum is a reserved keyword in C .
Typecasting as earlier discussed is a powerful tool and demands extreme care when being handled. Typecasting pointers in C has to be dealt with the same level of care. The language allows typecasting to be handled efficiently even by the pointers, allowing a very versatile usage of pointers and making the code user efficient. Meanwhile, the pointers as discussed earlier can be very tricky to handled at times and a single mistake can send the code crashing or possibly memory leak.
Two weeks ago, I explained to you a basic and easy sorting algorithm which was Selection Sort. Moving onwards, there is yet another basic algorithm by the name of Bubble Sort. It is known as Bubble sort because it brings the small values on the top of the list just like the light bubbles in water tend to come to the surface. Let us see how it works in depth.
So I have decided to put aside Sorting for some time and intended to discuss a few tidbits with you. This time I would share some interesting material on the swapping of two different variables. Swapping is one of the most frequently occurring processes taking place inside a Computer Machine. Then in many other Programs and Algorithms, swapping takes place as a sub-process. Sometimes it is user defined and sometimes not. So let us see how can we improve the swapping process.
Working with pointers in C requires a lot of practice to avoid memory leaks and dangling pointers. We discussed them in length in the previous post, Pointer Hazards in C . In object oriented paradigm, whenever you declare an object of user defined class type, a special function known as constructor is automatically invoked. Similarly when you want to copy an object to another object, copy constructor gets invoked. Writing an efficient and error free constructor is essential to the construction of a good program. In this post I shall explain how to write a good and efficient constructor and a copy constructor, paying special attention to pointer hazards.