Some basic rules of writing a C program

In this article, I am going to list some of the basic rules of writing a C program. I would strongly recommend following all these rules to code like a professional programmer.
Submitted by IncludeHelp, on May 13, 2018

C program is the set of statement written in C programming language. Each program should follow the standards (rules) to make your code working everywhere.

1) Comments/Documentation

Comments are not required, but the comments are as important as code. So it is first rule that you should remember to comment/document the code properly. Read more: How to comment the code?

What you can document?

Purpose of the code.

Name of the programmer, reviewer, code writing, editing date etc.

Resources (inputs) that will be used to run the code.

Explain each logic, what is that for and why you used?

You can also write note for the developers, in which you can explain your logic/algorithm in details.

3) Tokens, identifiers related rules

You must be aware about the C language tokens to differentiate what is keyword, what is identifier etc.

Some of the points that you must know:

Keywords are the reserved words in the compilers and you cannot use them for other purposes.

C language is cases sensitive programming language. Here, small case identifiers and uppercase identifiers are different. So, if you have declared a variable with name Num then you must have to use Num everywhere. You cannot use num, NUM etc instead of Num.

Same as keyword, library functions are also declared in the header files and you must have to include header file in the program. For example, if you are using sqrt() function to find the square root of any number, you will have to include math.h header file.

4) Rules about identifier/variable declarations

Only an alphabet or underscore (_) can be used as first letter of the identifier.

White spaces and other special characters are not allowed in an identifier name, if you have two words in a variables/identifier name, you can use either underscore (_) to separate them or you can also write identifier name in camel case style.For example: if you want to declare a variable to store roll number, the variable name should be roll_number or rollNumber or anything like that but you cannot use white spaces.

5) Code indentation

I have deal with many programmers who just write the code and they don’t care about the indentation, since indentation is not compulsory for the compiler. But it’s most important while writing the program. An indented code can read, edit easily.