Tip 1:
FIRST STEP BEFORE START CODING
It is strongly recommended, that always do some paper work to design your solutions for the given problems. This approach will eliminate number of bugs that appear at the initial stage. It indeed plays a vital role when you writing a programme that contains more than 100 lines.
Tip 2:
DON’T FORGET TO INITIALIZE VARIABLE
It is a better practice to initialize the variables before using them especially in pointers and in global variable cases. Otherwise this may lead to weird memory errors like memory fault or some capricious errors that are hard to trace.
Tip 3:
NAMING THE VARIABLE IS IMPORTANT
We must take special care while naming the variable else it will lead to mystification. Let us consider the following two code snippets
Code 1:
int main()
{
int i=3,j=5,k=0; k = i*j;
printf(“area of rectangle = %d”,k);
return 0;
}
Code 2:
int main()
{
int base=3,height=5,
rect_area=0;
rect_area = base*height;
printf(“area of rectangle = %d”,rect_area);
return 0;
}
The above two programs used to find the area of rectangle. However which one of it gives more meaning? Do the variables (i,j,k) in Code 1 give any sort of meaning? They lead to confusion, don’t they? Where as the variables (base, height, rect_area) in Code 2 give us more meaning than the Code 1. So always try to give meaningful names to the variable. |