Tips For C++ Programmers - Read & Learn
NOTE-> THESE TIPS ARE SUPPORTED IN DEV-C++ WHICH USES A GCC COMPILER. I SUGGEST EVERYONE TO USE DEV or VISUAL C++ BECAUSE IT WILL SURELY ENHANCE YOUR PROGRAMMING SKILLS AND INTELLIGENCE.
1) Most of us use clrscr( ); to clean up the output screen. Well, this function is not a standard function to be used in your program. Use system("cls"); which is included in stdlib.h this function is more preferable than clrscr();
2) While programming for C++, instead of
#include <iostream.h>
use
#include <iostream> using namespace std;as the programming environments have been developed and none of the people use the ancestor blue screen programming environment. Similarly, the header files ctype.h, assert.h etc can be directly writen as cctype, cassert (without .h extension)
3) In C++, using getch( ) to hold the output on screen is a bad practice. Which is not a standard function provided by ANSI C. Use
fflush (stdin); // cstdio header std::cin.get(); // iostream header
4) DO NOT USE void main( ) since it returns a garbage value to the main function, which makes it impossible to be called explicitly in some other program.
use int main( ) so that you know what value it returns.
5) And, at the end I'd like to tell something about presentation. Presentation of code is very important in all aspects. The code must be understandable not only by you but also to the other person. It doesn't matter to whom you are presenting the code. I've seen people (mostly my classmates) writing the code in very clumsy way, and when they ask me any doubt, I'm unable to understand their code, just because their way of presentation is too bad.
The same thing must be kept in mind while asking the doubts on the forums. Your codes must be understandable by the person who is seeing it, or else they loose interest in helping you out..
> Writing comments is a very good habit. Write a comment about the action of the statement in your code. It must be done for all the loops you're using. If you're able to determine where you are getting an error, write a comment indicating the error.
> Make your code more expanded and clear. Use the white spaces (space bar or tab keys ). They don't effect your program in anyway as the compiler skips all the white spaces used. But, it helps the user to understand the code easily.
ex:
int main() {printf("HELLO CEANS"); return 0;}the compiler faces no problem in faces no problem in executing the above code. But is it presented well?? Well, everyone knows NO! We can instead write it in different way asint main()
{
printf ("HELLO CEANS");
return 0;
}The same things can be done while using the loop conditions or conditional statements
// make your code look clear...
for(i = 0 ; i < condition ; i++) // spaces between the variables and operators
{ // opening and closing braces are in same line
............. // loop statements are well organized
.............
} So that's it for now! Have a good day! CHEERS

