Skip to main content

Posts

Showing posts from May, 2007

5 Common C++ Programming Mistakes

To err is human It is normal for programmers to make mistakes while learning c++ programming. Mistakes (or errors) are often caused by misconception in the programmers mind or by forgetting certain things. While syntax errors are easier to spot since the c++ compiler shows the related information but logical errors often remains unnoticed, and many a times the program works just as fine. It is not possible to completely eliminate errors by yourself but it is definitely possible to minimize them as a c++ programmer. Here I am listing 5 of the common mistakes (errors) that beginners commit (not sorted in any order). Mistake No. 1 Have a look at this C++ Program #include<iostream.h> void main(void) { int base,height,area; cout<<"Enter the base and height of the triangle:"; cin>>base>>height; area=0.5*base*height; cout<<endl<<"AREA:"<<area; } Here the variable area is such that sometimes its

Simple Problem in C++

Interchanging the values of two variables… What’s the big deal. You take one extra variable; put the first variable’s value in it, copy the value of the second variable to the first one and then copy the value of the extra variable to the first one and there you are! But what, if I say that you don’t have to use the third variable, let’s say because the memory is full and you are left with memory only sufficient for storing two variables. Doesn’t make sense. Huh! It makes sense if you want to gain programming skills because solving problems is the only way to do it. In this article we start with a simple one. So, how do we do it? It is not very big deal to interchange the values of two variables without using the third variable yet I have come across peoples who don’t think it can be done. To solve this problem we need to do two things (i)First we need to write down the method (algorithm) of doing it (ii0 Secondly, we need to write the c++ code from the algorithm. The Method Th

Half an Hour to Variables

I wrote this article yesterday when I was getting bored and was feeling too lazy, all thanks to the hot weather here. I planned of meeting my friends but at last I insisted on staying at home when I wrote this. Regarding the title, I thought that if it took me an hour to write it then you would have to hardly give Half an Hour to Variables. Now coming to the serious stuff… What is Variable During program run we need to manipulate data and the data to be manipulated are stored in memory locations known as variable. In the system memory, data are stored in memory locations such as 0x00243 which are not easy to remember if we have quite a lot of them. Variables are memory locations having a name so that different memory locations can be distinguished easily. Declaration and Initialization of Variables The declaration of variable generally takes the following form: type varname; Here type is any valid data type and varname is the variable name. Ex. int age; float temp; Static i

C++ Data Types in Detail

Data types are means to identify the type of data and associated operations of handling it. C++ provides a predefined set of data types for handling the data it uses. When variables are declared of a particular data type then the variable becomes the place where the data is stored and data types is the type of value(data) stored by that variable. Data can be of may types such as character, integer, real etc. since the data to be dealt with are of may types, a programming language must provide different data types. In C++ data types are of two types:- Fundamental Data Types : As the name suggests these are the atomic or the fundamental data types in C++. Earlier there was five of these (int, char, float, double and void) but later two new data types namely bool and wchar_t have been added. Int stores integer data or whole numbers such as 10, -340 etc., char stores any of the ASCII characters, float is used to store numbers having fractional part such as 10.097, double stores the sam

Introduction to C++ Programming

This article gives you an introduction to C++ Programming from ground level. This article won't teach you all the fundas of C++ programming rather it gives you the base to learn C++ programming, remember that for further learning, the base should be strong and this is what this article tries to do. It would let you know many fundas which will help you in further learning of the the language. C++ was developed in 1980s in the Bell Laboratories by Bjarne Stroustrup as an object oriented programming language. This language is considered by many as an extension of the programming language C. The extension of programming language C to create C++ is obtained by adding classes to C. This is why C++ was initially called “C with Classes”. The C++ programming language derives its name from the increment operator used in C, which increments the value of a variable. The symbolic name of C++ rightly indicates that this language is enhanced version of C. Features of C++ Programming Language:-